@ckeditor/ckeditor5-font 40.0.0 → 40.2.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/CHANGELOG.md +19 -19
- package/LICENSE.md +3 -3
- 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
- package/build/font.js.map +0 -1
|
@@ -1,44 +1,44 @@
|
|
|
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/fontsizeediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
|
9
|
-
/**
|
|
10
|
-
* The font size editing feature.
|
|
11
|
-
*
|
|
12
|
-
* It introduces the {@link module:font/fontsize/fontsizecommand~FontSizeCommand command} and the `fontSize`
|
|
13
|
-
* attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
|
|
14
|
-
* as a `<span>` element with either:
|
|
15
|
-
* * a style attribute (`<span style="font-size:12px">...</span>`),
|
|
16
|
-
* * or a class attribute (`<span class="text-small">...</span>`)
|
|
17
|
-
*
|
|
18
|
-
* depending on the {@link module:font/fontconfig~FontSizeConfig configuration}.
|
|
19
|
-
*/
|
|
20
|
-
export default class FontSizeEditing extends Plugin {
|
|
21
|
-
/**
|
|
22
|
-
* @inheritDoc
|
|
23
|
-
*/
|
|
24
|
-
static get pluginName(): "FontSizeEditing";
|
|
25
|
-
/**
|
|
26
|
-
* @inheritDoc
|
|
27
|
-
*/
|
|
28
|
-
constructor(editor: Editor);
|
|
29
|
-
/**
|
|
30
|
-
* @inheritDoc
|
|
31
|
-
*/
|
|
32
|
-
init(): void;
|
|
33
|
-
/**
|
|
34
|
-
* These converters enable keeping any value found as `style="font-size: *"` as a value of an attribute on a text even
|
|
35
|
-
* if it is not defined in the plugin configuration.
|
|
36
|
-
*
|
|
37
|
-
* @param definition Converter definition out of input data.
|
|
38
|
-
*/
|
|
39
|
-
private _prepareAnyValueConverters;
|
|
40
|
-
/**
|
|
41
|
-
* Adds support for legacy `<font size="..">` formatting.
|
|
42
|
-
*/
|
|
43
|
-
private _prepareCompatibilityConverter;
|
|
44
|
-
}
|
|
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/fontsizeediting
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
|
9
|
+
/**
|
|
10
|
+
* The font size editing feature.
|
|
11
|
+
*
|
|
12
|
+
* It introduces the {@link module:font/fontsize/fontsizecommand~FontSizeCommand command} and the `fontSize`
|
|
13
|
+
* attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
|
|
14
|
+
* as a `<span>` element with either:
|
|
15
|
+
* * a style attribute (`<span style="font-size:12px">...</span>`),
|
|
16
|
+
* * or a class attribute (`<span class="text-small">...</span>`)
|
|
17
|
+
*
|
|
18
|
+
* depending on the {@link module:font/fontconfig~FontSizeConfig configuration}.
|
|
19
|
+
*/
|
|
20
|
+
export default class FontSizeEditing extends Plugin {
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
static get pluginName(): "FontSizeEditing";
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
constructor(editor: Editor);
|
|
29
|
+
/**
|
|
30
|
+
* @inheritDoc
|
|
31
|
+
*/
|
|
32
|
+
init(): void;
|
|
33
|
+
/**
|
|
34
|
+
* These converters enable keeping any value found as `style="font-size: *"` as a value of an attribute on a text even
|
|
35
|
+
* if it is not defined in the plugin configuration.
|
|
36
|
+
*
|
|
37
|
+
* @param definition Converter definition out of input data.
|
|
38
|
+
*/
|
|
39
|
+
private _prepareAnyValueConverters;
|
|
40
|
+
/**
|
|
41
|
+
* Adds support for legacy `<font size="..">` formatting.
|
|
42
|
+
*/
|
|
43
|
+
private _prepareCompatibilityConverter;
|
|
44
|
+
}
|
|
@@ -1,165 +1,165 @@
|
|
|
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/fontsizeediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { CKEditorError } from 'ckeditor5/src/utils';
|
|
10
|
-
import { isLength, isPercentage } from 'ckeditor5/src/engine';
|
|
11
|
-
import FontSizeCommand from './fontsizecommand';
|
|
12
|
-
import { normalizeOptions } from './utils';
|
|
13
|
-
import { buildDefinition, FONT_SIZE } from '../utils';
|
|
14
|
-
// Mapping of `<font size="..">` styling to CSS's `font-size` values.
|
|
15
|
-
const styleFontSize = [
|
|
16
|
-
'x-small',
|
|
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 default class FontSizeEditing extends Plugin {
|
|
37
|
-
/**
|
|
38
|
-
* @inheritDoc
|
|
39
|
-
*/
|
|
40
|
-
static get pluginName() {
|
|
41
|
-
return 'FontSizeEditing';
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* @inheritDoc
|
|
45
|
-
*/
|
|
46
|
-
constructor(editor) {
|
|
47
|
-
super(editor);
|
|
48
|
-
// Define default configuration using named presets.
|
|
49
|
-
editor.config.define(FONT_SIZE, {
|
|
50
|
-
options: [
|
|
51
|
-
'tiny',
|
|
52
|
-
'small',
|
|
53
|
-
'default',
|
|
54
|
-
'big',
|
|
55
|
-
'huge'
|
|
56
|
-
],
|
|
57
|
-
supportAllValues: false
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @inheritDoc
|
|
62
|
-
*/
|
|
63
|
-
init() {
|
|
64
|
-
const editor = this.editor;
|
|
65
|
-
// Allow fontSize attribute on text nodes.
|
|
66
|
-
editor.model.schema.extend('$text', { allowAttributes: FONT_SIZE });
|
|
67
|
-
editor.model.schema.setAttributeProperties(FONT_SIZE, {
|
|
68
|
-
isFormatting: true,
|
|
69
|
-
copyOnEnter: true
|
|
70
|
-
});
|
|
71
|
-
const supportAllValues = editor.config.get('fontSize.supportAllValues');
|
|
72
|
-
// Define view to model conversion.
|
|
73
|
-
const options = normalizeOptions(this.editor.config.get('fontSize.options'))
|
|
74
|
-
.filter(item => item.model);
|
|
75
|
-
const definition = buildDefinition(FONT_SIZE, options);
|
|
76
|
-
// Set-up the two-way conversion.
|
|
77
|
-
if (supportAllValues) {
|
|
78
|
-
this._prepareAnyValueConverters(definition);
|
|
79
|
-
this._prepareCompatibilityConverter();
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
editor.conversion.attributeToElement(definition);
|
|
83
|
-
}
|
|
84
|
-
// Add FontSize command.
|
|
85
|
-
editor.commands.add(FONT_SIZE, new FontSizeCommand(editor));
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* These converters enable keeping any value found as `style="font-size: *"` as a value of an attribute on a text even
|
|
89
|
-
* if it is not defined in the plugin configuration.
|
|
90
|
-
*
|
|
91
|
-
* @param definition Converter definition out of input data.
|
|
92
|
-
*/
|
|
93
|
-
_prepareAnyValueConverters(definition) {
|
|
94
|
-
const editor = this.editor;
|
|
95
|
-
// If `fontSize.supportAllValues=true`, we do not allow to use named presets in the plugin's configuration.
|
|
96
|
-
const presets = definition.model.values.filter((value) => {
|
|
97
|
-
return !isLength(String(value)) && !isPercentage(String(value));
|
|
98
|
-
});
|
|
99
|
-
if (presets.length) {
|
|
100
|
-
/**
|
|
101
|
-
* If {@link module:font/fontconfig~FontSizeConfig#supportAllValues `config.fontSize.supportAllValues`} is `true`,
|
|
102
|
-
* you need to use numerical values as font size options.
|
|
103
|
-
*
|
|
104
|
-
* See valid examples described in the {@link module:font/fontconfig~FontSizeConfig#options plugin configuration}.
|
|
105
|
-
*
|
|
106
|
-
* @error font-size-invalid-use-of-named-presets
|
|
107
|
-
* @param {Array.<String>} presets Invalid values.
|
|
108
|
-
*/
|
|
109
|
-
throw new CKEditorError('font-size-invalid-use-of-named-presets', null, { presets });
|
|
110
|
-
}
|
|
111
|
-
editor.conversion.for('downcast').attributeToElement({
|
|
112
|
-
model: FONT_SIZE,
|
|
113
|
-
view: (attributeValue, { writer }) => {
|
|
114
|
-
if (!attributeValue) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
return writer.createAttributeElement('span', { style: 'font-size:' + attributeValue }, { priority: 7 });
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
editor.conversion.for('upcast').elementToAttribute({
|
|
121
|
-
model: {
|
|
122
|
-
key: FONT_SIZE,
|
|
123
|
-
value: (viewElement) => viewElement.getStyle('font-size')
|
|
124
|
-
},
|
|
125
|
-
view: {
|
|
126
|
-
name: 'span',
|
|
127
|
-
styles: {
|
|
128
|
-
'font-size': /.*/
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Adds support for legacy `<font size="..">` formatting.
|
|
135
|
-
*/
|
|
136
|
-
_prepareCompatibilityConverter() {
|
|
137
|
-
const editor = this.editor;
|
|
138
|
-
editor.conversion.for('upcast').elementToAttribute({
|
|
139
|
-
view: {
|
|
140
|
-
name: 'font',
|
|
141
|
-
attributes: {
|
|
142
|
-
// Documentation mentions sizes from 1 to 7. To handle old content we support all values
|
|
143
|
-
// up to 999 but clamp it to the valid range. Why 999? It should cover accidental values
|
|
144
|
-
// similar to percentage, e.g. 100%, 200% which could be the usual mistake for font size.
|
|
145
|
-
'size': /^[+-]?\d{1,3}$/
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
model: {
|
|
149
|
-
key: FONT_SIZE,
|
|
150
|
-
value: (viewElement) => {
|
|
151
|
-
const value = viewElement.getAttribute('size');
|
|
152
|
-
const isRelative = value[0] === '-' || value[0] === '+';
|
|
153
|
-
let size = parseInt(value, 10);
|
|
154
|
-
if (isRelative) {
|
|
155
|
-
// Add relative size (which can be negative) to the default size = 3.
|
|
156
|
-
size = 3 + size;
|
|
157
|
-
}
|
|
158
|
-
const maxSize = styleFontSize.length - 1;
|
|
159
|
-
const clampedSize = Math.min(Math.max(size, 0), maxSize);
|
|
160
|
-
return styleFontSize[clampedSize];
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
|
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/fontsizeediting
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { CKEditorError } from 'ckeditor5/src/utils';
|
|
10
|
+
import { isLength, isPercentage } from 'ckeditor5/src/engine';
|
|
11
|
+
import FontSizeCommand from './fontsizecommand';
|
|
12
|
+
import { normalizeOptions } from './utils';
|
|
13
|
+
import { buildDefinition, FONT_SIZE } from '../utils';
|
|
14
|
+
// Mapping of `<font size="..">` styling to CSS's `font-size` values.
|
|
15
|
+
const styleFontSize = [
|
|
16
|
+
'x-small',
|
|
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 default class FontSizeEditing extends Plugin {
|
|
37
|
+
/**
|
|
38
|
+
* @inheritDoc
|
|
39
|
+
*/
|
|
40
|
+
static get pluginName() {
|
|
41
|
+
return 'FontSizeEditing';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @inheritDoc
|
|
45
|
+
*/
|
|
46
|
+
constructor(editor) {
|
|
47
|
+
super(editor);
|
|
48
|
+
// Define default configuration using named presets.
|
|
49
|
+
editor.config.define(FONT_SIZE, {
|
|
50
|
+
options: [
|
|
51
|
+
'tiny',
|
|
52
|
+
'small',
|
|
53
|
+
'default',
|
|
54
|
+
'big',
|
|
55
|
+
'huge'
|
|
56
|
+
],
|
|
57
|
+
supportAllValues: false
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @inheritDoc
|
|
62
|
+
*/
|
|
63
|
+
init() {
|
|
64
|
+
const editor = this.editor;
|
|
65
|
+
// Allow fontSize attribute on text nodes.
|
|
66
|
+
editor.model.schema.extend('$text', { allowAttributes: FONT_SIZE });
|
|
67
|
+
editor.model.schema.setAttributeProperties(FONT_SIZE, {
|
|
68
|
+
isFormatting: true,
|
|
69
|
+
copyOnEnter: true
|
|
70
|
+
});
|
|
71
|
+
const supportAllValues = editor.config.get('fontSize.supportAllValues');
|
|
72
|
+
// Define view to model conversion.
|
|
73
|
+
const options = normalizeOptions(this.editor.config.get('fontSize.options'))
|
|
74
|
+
.filter(item => item.model);
|
|
75
|
+
const definition = buildDefinition(FONT_SIZE, options);
|
|
76
|
+
// Set-up the two-way conversion.
|
|
77
|
+
if (supportAllValues) {
|
|
78
|
+
this._prepareAnyValueConverters(definition);
|
|
79
|
+
this._prepareCompatibilityConverter();
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
editor.conversion.attributeToElement(definition);
|
|
83
|
+
}
|
|
84
|
+
// Add FontSize command.
|
|
85
|
+
editor.commands.add(FONT_SIZE, new FontSizeCommand(editor));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* These converters enable keeping any value found as `style="font-size: *"` as a value of an attribute on a text even
|
|
89
|
+
* if it is not defined in the plugin configuration.
|
|
90
|
+
*
|
|
91
|
+
* @param definition Converter definition out of input data.
|
|
92
|
+
*/
|
|
93
|
+
_prepareAnyValueConverters(definition) {
|
|
94
|
+
const editor = this.editor;
|
|
95
|
+
// If `fontSize.supportAllValues=true`, we do not allow to use named presets in the plugin's configuration.
|
|
96
|
+
const presets = definition.model.values.filter((value) => {
|
|
97
|
+
return !isLength(String(value)) && !isPercentage(String(value));
|
|
98
|
+
});
|
|
99
|
+
if (presets.length) {
|
|
100
|
+
/**
|
|
101
|
+
* If {@link module:font/fontconfig~FontSizeConfig#supportAllValues `config.fontSize.supportAllValues`} is `true`,
|
|
102
|
+
* you need to use numerical values as font size options.
|
|
103
|
+
*
|
|
104
|
+
* See valid examples described in the {@link module:font/fontconfig~FontSizeConfig#options plugin configuration}.
|
|
105
|
+
*
|
|
106
|
+
* @error font-size-invalid-use-of-named-presets
|
|
107
|
+
* @param {Array.<String>} presets Invalid values.
|
|
108
|
+
*/
|
|
109
|
+
throw new CKEditorError('font-size-invalid-use-of-named-presets', null, { presets });
|
|
110
|
+
}
|
|
111
|
+
editor.conversion.for('downcast').attributeToElement({
|
|
112
|
+
model: FONT_SIZE,
|
|
113
|
+
view: (attributeValue, { writer }) => {
|
|
114
|
+
if (!attributeValue) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
return writer.createAttributeElement('span', { style: 'font-size:' + attributeValue }, { priority: 7 });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
editor.conversion.for('upcast').elementToAttribute({
|
|
121
|
+
model: {
|
|
122
|
+
key: FONT_SIZE,
|
|
123
|
+
value: (viewElement) => viewElement.getStyle('font-size')
|
|
124
|
+
},
|
|
125
|
+
view: {
|
|
126
|
+
name: 'span',
|
|
127
|
+
styles: {
|
|
128
|
+
'font-size': /.*/
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Adds support for legacy `<font size="..">` formatting.
|
|
135
|
+
*/
|
|
136
|
+
_prepareCompatibilityConverter() {
|
|
137
|
+
const editor = this.editor;
|
|
138
|
+
editor.conversion.for('upcast').elementToAttribute({
|
|
139
|
+
view: {
|
|
140
|
+
name: 'font',
|
|
141
|
+
attributes: {
|
|
142
|
+
// Documentation mentions sizes from 1 to 7. To handle old content we support all values
|
|
143
|
+
// up to 999 but clamp it to the valid range. Why 999? It should cover accidental values
|
|
144
|
+
// similar to percentage, e.g. 100%, 200% which could be the usual mistake for font size.
|
|
145
|
+
'size': /^[+-]?\d{1,3}$/
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
model: {
|
|
149
|
+
key: FONT_SIZE,
|
|
150
|
+
value: (viewElement) => {
|
|
151
|
+
const value = viewElement.getAttribute('size');
|
|
152
|
+
const isRelative = value[0] === '-' || value[0] === '+';
|
|
153
|
+
let size = parseInt(value, 10);
|
|
154
|
+
if (isRelative) {
|
|
155
|
+
// Add relative size (which can be negative) to the default size = 3.
|
|
156
|
+
size = 3 + size;
|
|
157
|
+
}
|
|
158
|
+
const maxSize = styleFontSize.length - 1;
|
|
159
|
+
const clampedSize = Math.min(Math.max(size, 0), maxSize);
|
|
160
|
+
return styleFontSize[clampedSize];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -1,31 +1,31 @@
|
|
|
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/fontsizeui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import '../../theme/fontsize.css';
|
|
10
|
-
/**
|
|
11
|
-
* The font size UI plugin. It introduces the `'fontSize'` dropdown.
|
|
12
|
-
*/
|
|
13
|
-
export default class FontSizeUI extends Plugin {
|
|
14
|
-
/**
|
|
15
|
-
* @inheritDoc
|
|
16
|
-
*/
|
|
17
|
-
static get pluginName(): "FontSizeUI";
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
init(): void;
|
|
22
|
-
/**
|
|
23
|
-
* Returns options as defined in `config.fontSize.options` but processed to account for
|
|
24
|
-
* editor localization, i.e. to display {@link module:font/fontconfig~FontSizeOption}
|
|
25
|
-
* in the correct language.
|
|
26
|
-
*
|
|
27
|
-
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
|
|
28
|
-
* when the user configuration is defined because the editor does not exist yet.
|
|
29
|
-
*/
|
|
30
|
-
private _getLocalizedOptions;
|
|
31
|
-
}
|
|
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/fontsizeui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import '../../theme/fontsize.css';
|
|
10
|
+
/**
|
|
11
|
+
* The font size UI plugin. It introduces the `'fontSize'` dropdown.
|
|
12
|
+
*/
|
|
13
|
+
export default class FontSizeUI extends Plugin {
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
static get pluginName(): "FontSizeUI";
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
init(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Returns options as defined in `config.fontSize.options` but processed to account for
|
|
24
|
+
* editor localization, i.e. to display {@link module:font/fontconfig~FontSizeOption}
|
|
25
|
+
* in the correct language.
|
|
26
|
+
*
|
|
27
|
+
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
|
|
28
|
+
* when the user configuration is defined because the editor does not exist yet.
|
|
29
|
+
*/
|
|
30
|
+
private _getLocalizedOptions;
|
|
31
|
+
}
|