@ckeditor/ckeditor5-font 36.0.0 → 37.0.0-alpha.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.
Files changed (54) hide show
  1. package/build/font.js +1 -1
  2. package/package.json +20 -15
  3. package/src/documentcolorcollection.d.ts +47 -0
  4. package/src/documentcolorcollection.js +34 -63
  5. package/src/font.d.ts +34 -0
  6. package/src/font.js +12 -19
  7. package/src/fontbackgroundcolor/fontbackgroundcolorcommand.d.ts +32 -0
  8. package/src/fontbackgroundcolor/fontbackgroundcolorcommand.js +9 -15
  9. package/src/fontbackgroundcolor/fontbackgroundcolorediting.d.ts +31 -0
  10. package/src/fontbackgroundcolor/fontbackgroundcolorediting.js +102 -115
  11. package/src/fontbackgroundcolor/fontbackgroundcolorui.d.ts +27 -0
  12. package/src/fontbackgroundcolor/fontbackgroundcolorui.js +18 -25
  13. package/src/fontbackgroundcolor.d.ts +33 -0
  14. package/src/fontbackgroundcolor.js +12 -165
  15. package/src/fontcolor/fontcolorcommand.d.ts +31 -0
  16. package/src/fontcolor/fontcolorcommand.js +9 -15
  17. package/src/fontcolor/fontcolorediting.d.ts +31 -0
  18. package/src/fontcolor/fontcolorediting.js +115 -128
  19. package/src/fontcolor/fontcolorui.d.ts +27 -0
  20. package/src/fontcolor/fontcolorui.js +18 -25
  21. package/src/fontcolor.d.ts +29 -0
  22. package/src/fontcolor.js +12 -168
  23. package/src/fontcommand.d.ts +46 -0
  24. package/src/fontcommand.js +54 -78
  25. package/src/fontconfig.d.ts +399 -0
  26. package/src/fontconfig.js +5 -0
  27. package/src/fontfamily/fontfamilycommand.d.ts +31 -0
  28. package/src/fontfamily/fontfamilycommand.js +9 -15
  29. package/src/fontfamily/fontfamilyediting.d.ts +45 -0
  30. package/src/fontfamily/fontfamilyediting.js +96 -116
  31. package/src/fontfamily/fontfamilyui.d.ts +35 -0
  32. package/src/fontfamily/fontfamilyui.js +90 -122
  33. package/src/fontfamily/utils.d.ts +15 -0
  34. package/src/fontfamily/utils.js +66 -79
  35. package/src/fontfamily.d.ts +29 -0
  36. package/src/fontfamily.js +12 -112
  37. package/src/fontsize/fontsizecommand.d.ts +31 -0
  38. package/src/fontsize/fontsizecommand.js +9 -15
  39. package/src/fontsize/fontsizeediting.d.ts +50 -0
  40. package/src/fontsize/fontsizeediting.js +138 -169
  41. package/src/fontsize/fontsizeui.d.ts +36 -0
  42. package/src/fontsize/fontsizeui.js +98 -130
  43. package/src/fontsize/utils.d.ts +12 -0
  44. package/src/fontsize/utils.js +145 -174
  45. package/src/fontsize.d.ts +40 -0
  46. package/src/fontsize.js +21 -141
  47. package/src/index.d.ts +20 -0
  48. package/src/index.js +0 -2
  49. package/src/ui/colortableview.d.ts +167 -0
  50. package/src/ui/colortableview.js +240 -416
  51. package/src/ui/colorui.d.ts +64 -0
  52. package/src/ui/colorui.js +79 -132
  53. package/src/utils.d.ts +77 -0
  54. package/src/utils.js +42 -72
@@ -2,31 +2,27 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module font/fontsize/fontsizeediting
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
9
  import { CKEditorError } from 'ckeditor5/src/utils';
12
10
  import { isLength, isPercentage } from 'ckeditor5/src/engine';
13
-
14
11
  import FontSizeCommand from './fontsizecommand';
15
12
  import { normalizeOptions } from './utils';
16
13
  import { buildDefinition, FONT_SIZE } from '../utils';
17
-
14
+ import '../fontconfig';
18
15
  // Mapping of `<font size="..">` styling to CSS's `font-size` values.
19
16
  const styleFontSize = [
20
- 'x-small', // Size "0" equal to "1".
21
- 'x-small',
22
- 'small',
23
- 'medium',
24
- 'large',
25
- 'x-large',
26
- 'xx-large',
27
- 'xxx-large'
17
+ 'x-small',
18
+ 'x-small',
19
+ 'small',
20
+ 'medium',
21
+ 'large',
22
+ 'x-large',
23
+ 'xx-large',
24
+ 'xxx-large'
28
25
  ];
29
-
30
26
  /**
31
27
  * The font size editing feature.
32
28
  *
@@ -36,162 +32,135 @@ const styleFontSize = [
36
32
  * * a style attribute (`<span style="font-size:12px">...</span>`),
37
33
  * * or a class attribute (`<span class="text-small">...</span>`)
38
34
  *
39
- * depending on the {@link module:font/fontsize~FontSizeConfig configuration}.
40
- *
41
- * @extends module:core/plugin~Plugin
35
+ * depending on the {@link module:font/fontconfig~FontSizeConfig configuration}.
42
36
  */
43
37
  export default class FontSizeEditing extends Plugin {
44
- /**
45
- * @inheritDoc
46
- */
47
- static get pluginName() {
48
- return 'FontSizeEditing';
49
- }
50
-
51
- /**
52
- * @inheritDoc
53
- */
54
- constructor( editor ) {
55
- super( editor );
56
-
57
- // Define default configuration using named presets.
58
- editor.config.define( FONT_SIZE, {
59
- options: [
60
- 'tiny',
61
- 'small',
62
- 'default',
63
- 'big',
64
- 'huge'
65
- ],
66
- supportAllValues: false
67
- } );
68
- }
69
-
70
- /**
71
- * @inheritDoc
72
- */
73
- init() {
74
- const editor = this.editor;
75
-
76
- // Allow fontSize attribute on text nodes.
77
- editor.model.schema.extend( '$text', { allowAttributes: FONT_SIZE } );
78
- editor.model.schema.setAttributeProperties( FONT_SIZE, {
79
- isFormatting: true,
80
- copyOnEnter: true
81
- } );
82
-
83
- const supportAllValues = editor.config.get( 'fontSize.supportAllValues' );
84
-
85
- // Define view to model conversion.
86
- const options = normalizeOptions( this.editor.config.get( 'fontSize.options' ) )
87
- .filter( item => item.model );
88
- const definition = buildDefinition( FONT_SIZE, options );
89
-
90
- // Set-up the two-way conversion.
91
- if ( supportAllValues ) {
92
- this._prepareAnyValueConverters( definition );
93
- this._prepareCompatibilityConverter();
94
- } else {
95
- editor.conversion.attributeToElement( definition );
96
- }
97
-
98
- // Add FontSize command.
99
- editor.commands.add( FONT_SIZE, new FontSizeCommand( editor ) );
100
- }
101
-
102
- /**
103
- * These converters enable keeping any value found as `style="font-size: *"` as a value of an attribute on a text even
104
- * if it is not defined in the plugin configuration.
105
- *
106
- * @param {Object} definition {@link module:engine/conversion/conversion~ConverterDefinition Converter definition} out of input data.
107
- * @private
108
- */
109
- _prepareAnyValueConverters( definition ) {
110
- const editor = this.editor;
111
-
112
- // If `fontSize.supportAllValues=true`, we do not allow to use named presets in the plugin's configuration.
113
- const presets = definition.model.values.filter( value => {
114
- return !isLength( String( value ) ) && !isPercentage( String( value ) );
115
- } );
116
-
117
- if ( presets.length ) {
118
- /**
119
- * If {@link module:font/fontsize~FontSizeConfig#supportAllValues `config.fontSize.supportAllValues`} is `true`,
120
- * you need to use numerical values as font size options.
121
- *
122
- * See valid examples described in the {@link module:font/fontsize~FontSizeConfig#options plugin configuration}.
123
- *
124
- * @error font-size-invalid-use-of-named-presets
125
- * @param {Array.<String>} presets Invalid values.
126
- */
127
- throw new CKEditorError(
128
- 'font-size-invalid-use-of-named-presets',
129
- null, { presets }
130
- );
131
- }
132
-
133
- editor.conversion.for( 'downcast' ).attributeToElement( {
134
- model: FONT_SIZE,
135
- view: ( attributeValue, { writer } ) => {
136
- if ( !attributeValue ) {
137
- return;
138
- }
139
-
140
- return writer.createAttributeElement( 'span', { style: 'font-size:' + attributeValue }, { priority: 7 } );
141
- }
142
- } );
143
-
144
- editor.conversion.for( 'upcast' ).elementToAttribute( {
145
- model: {
146
- key: FONT_SIZE,
147
- value: viewElement => viewElement.getStyle( 'font-size' )
148
- },
149
- view: {
150
- name: 'span',
151
- styles: {
152
- 'font-size': /.*/
153
- }
154
- }
155
- } );
156
- }
157
-
158
- /**
159
- * Adds support for legacy `<font size="..">` formatting.
160
- *
161
- * @private
162
- */
163
- _prepareCompatibilityConverter() {
164
- const editor = this.editor;
165
-
166
- editor.conversion.for( 'upcast' ).elementToAttribute( {
167
- view: {
168
- name: 'font',
169
- attributes: {
170
- // Documentation mentions sizes from 1 to 7. To handle old content we support all values
171
- // up to 999 but clamp it to the valid range. Why 999? It should cover accidental values
172
- // similar to percentage, e.g. 100%, 200% which could be the usual mistake for font size.
173
- 'size': /^[+-]?\d{1,3}$/
174
- }
175
- },
176
- model: {
177
- key: FONT_SIZE,
178
- value: viewElement => {
179
- const value = viewElement.getAttribute( 'size' );
180
- const isRelative = value[ 0 ] === '-' || value[ 0 ] === '+';
181
-
182
- let size = parseInt( value, 10 );
183
-
184
- if ( isRelative ) {
185
- // Add relative size (which can be negative) to the default size = 3.
186
- size = 3 + size;
187
- }
188
-
189
- const maxSize = styleFontSize.length - 1;
190
- const clampedSize = Math.min( Math.max( size, 0 ), maxSize );
191
-
192
- return styleFontSize[ clampedSize ];
193
- }
194
- }
195
- } );
196
- }
38
+ /**
39
+ * @inheritDoc
40
+ */
41
+ static get pluginName() {
42
+ return 'FontSizeEditing';
43
+ }
44
+ /**
45
+ * @inheritDoc
46
+ */
47
+ constructor(editor) {
48
+ super(editor);
49
+ // Define default configuration using named presets.
50
+ editor.config.define(FONT_SIZE, {
51
+ options: [
52
+ 'tiny',
53
+ 'small',
54
+ 'default',
55
+ 'big',
56
+ 'huge'
57
+ ],
58
+ supportAllValues: false
59
+ });
60
+ }
61
+ /**
62
+ * @inheritDoc
63
+ */
64
+ init() {
65
+ const editor = this.editor;
66
+ // Allow fontSize attribute on text nodes.
67
+ editor.model.schema.extend('$text', { allowAttributes: FONT_SIZE });
68
+ editor.model.schema.setAttributeProperties(FONT_SIZE, {
69
+ isFormatting: true,
70
+ copyOnEnter: true
71
+ });
72
+ const supportAllValues = editor.config.get('fontSize.supportAllValues');
73
+ // Define view to model conversion.
74
+ const options = normalizeOptions(this.editor.config.get('fontSize.options'))
75
+ .filter(item => item.model);
76
+ const definition = buildDefinition(FONT_SIZE, options);
77
+ // Set-up the two-way conversion.
78
+ if (supportAllValues) {
79
+ this._prepareAnyValueConverters(definition);
80
+ this._prepareCompatibilityConverter();
81
+ }
82
+ else {
83
+ editor.conversion.attributeToElement(definition);
84
+ }
85
+ // Add FontSize command.
86
+ editor.commands.add(FONT_SIZE, new FontSizeCommand(editor));
87
+ }
88
+ /**
89
+ * These converters enable keeping any value found as `style="font-size: *"` as a value of an attribute on a text even
90
+ * if it is not defined in the plugin configuration.
91
+ *
92
+ * @param definition Converter definition out of input data.
93
+ */
94
+ _prepareAnyValueConverters(definition) {
95
+ const editor = this.editor;
96
+ // If `fontSize.supportAllValues=true`, we do not allow to use named presets in the plugin's configuration.
97
+ const presets = definition.model.values.filter((value) => {
98
+ return !isLength(String(value)) && !isPercentage(String(value));
99
+ });
100
+ if (presets.length) {
101
+ /**
102
+ * If {@link module:font/fontconfig~FontSizeConfig#supportAllValues `config.fontSize.supportAllValues`} is `true`,
103
+ * you need to use numerical values as font size options.
104
+ *
105
+ * See valid examples described in the {@link module:font/fontconfig~FontSizeConfig#options plugin configuration}.
106
+ *
107
+ * @error font-size-invalid-use-of-named-presets
108
+ * @param {Array.<String>} presets Invalid values.
109
+ */
110
+ throw new CKEditorError('font-size-invalid-use-of-named-presets', null, { presets });
111
+ }
112
+ editor.conversion.for('downcast').attributeToElement({
113
+ model: FONT_SIZE,
114
+ view: (attributeValue, { writer }) => {
115
+ if (!attributeValue) {
116
+ return;
117
+ }
118
+ return writer.createAttributeElement('span', { style: 'font-size:' + attributeValue }, { priority: 7 });
119
+ }
120
+ });
121
+ editor.conversion.for('upcast').elementToAttribute({
122
+ model: {
123
+ key: FONT_SIZE,
124
+ value: (viewElement) => viewElement.getStyle('font-size')
125
+ },
126
+ view: {
127
+ name: 'span',
128
+ styles: {
129
+ 'font-size': /.*/
130
+ }
131
+ }
132
+ });
133
+ }
134
+ /**
135
+ * Adds support for legacy `<font size="..">` formatting.
136
+ */
137
+ _prepareCompatibilityConverter() {
138
+ const editor = this.editor;
139
+ editor.conversion.for('upcast').elementToAttribute({
140
+ view: {
141
+ name: 'font',
142
+ attributes: {
143
+ // Documentation mentions sizes from 1 to 7. To handle old content we support all values
144
+ // up to 999 but clamp it to the valid range. Why 999? It should cover accidental values
145
+ // similar to percentage, e.g. 100%, 200% which could be the usual mistake for font size.
146
+ 'size': /^[+-]?\d{1,3}$/
147
+ }
148
+ },
149
+ model: {
150
+ key: FONT_SIZE,
151
+ value: (viewElement) => {
152
+ const value = viewElement.getAttribute('size');
153
+ const isRelative = value[0] === '-' || value[0] === '+';
154
+ let size = parseInt(value, 10);
155
+ if (isRelative) {
156
+ // Add relative size (which can be negative) to the default size = 3.
157
+ size = 3 + size;
158
+ }
159
+ const maxSize = styleFontSize.length - 1;
160
+ const clampedSize = Math.min(Math.max(size, 0), maxSize);
161
+ return styleFontSize[clampedSize];
162
+ }
163
+ }
164
+ });
165
+ }
197
166
  }
@@ -0,0 +1,36 @@
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
+ }
32
+ declare module '@ckeditor/ckeditor5-core' {
33
+ interface PluginsMap {
34
+ [FontSizeUI.pluginName]: FontSizeUI;
35
+ }
36
+ }
@@ -2,148 +2,116 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module font/fontsize/fontsizeui
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
9
  import { Model, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
12
10
  import { Collection } from 'ckeditor5/src/utils';
13
-
14
11
  import { normalizeOptions } from './utils';
15
12
  import { FONT_SIZE } from '../utils';
16
-
17
- import fontSizeIcon from '../../theme/icons/font-size.svg';
18
13
  import '../../theme/fontsize.css';
19
-
14
+ import fontSizeIcon from '../../theme/icons/font-size.svg';
20
15
  /**
21
16
  * The font size UI plugin. It introduces the `'fontSize'` dropdown.
22
- *
23
- * @extends module:core/plugin~Plugin
24
17
  */
25
18
  export default class FontSizeUI extends Plugin {
26
- /**
27
- * @inheritDoc
28
- */
29
- static get pluginName() {
30
- return 'FontSizeUI';
31
- }
32
-
33
- /**
34
- * @inheritDoc
35
- */
36
- init() {
37
- const editor = this.editor;
38
- const t = editor.t;
39
-
40
- const options = this._getLocalizedOptions();
41
-
42
- const command = editor.commands.get( FONT_SIZE );
43
-
44
- // Register UI component.
45
- editor.ui.componentFactory.add( FONT_SIZE, locale => {
46
- const dropdownView = createDropdown( locale );
47
-
48
- addListToDropdown( dropdownView, () => _prepareListOptions( options, command ) );
49
-
50
- // Create dropdown model.
51
- dropdownView.buttonView.set( {
52
- label: t( 'Font Size' ),
53
- icon: fontSizeIcon,
54
- tooltip: true
55
- } );
56
-
57
- dropdownView.extendTemplate( {
58
- attributes: {
59
- class: [
60
- 'ck-font-size-dropdown'
61
- ]
62
- }
63
- } );
64
-
65
- dropdownView.bind( 'isEnabled' ).to( command );
66
-
67
- // Execute command when an item from the dropdown is selected.
68
- this.listenTo( dropdownView, 'execute', evt => {
69
- editor.execute( evt.source.commandName, { value: evt.source.commandParam } );
70
- editor.editing.view.focus();
71
- } );
72
-
73
- return dropdownView;
74
- } );
75
- }
76
-
77
- /**
78
- * Returns options as defined in `config.fontSize.options` but processed to account for
79
- * editor localization, i.e. to display {@link module:font/fontsize~FontSizeOption}
80
- * in the correct language.
81
- *
82
- * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
83
- * when the user configuration is defined because the editor does not exist yet.
84
- *
85
- * @private
86
- * @returns {Array.<module:font/fontsize~FontSizeOption>}.
87
- */
88
- _getLocalizedOptions() {
89
- const editor = this.editor;
90
- const t = editor.t;
91
-
92
- const localizedTitles = {
93
- Default: t( 'Default' ),
94
- Tiny: t( 'Tiny' ),
95
- Small: t( 'Small' ),
96
- Big: t( 'Big' ),
97
- Huge: t( 'Huge' )
98
- };
99
-
100
- const options = normalizeOptions( editor.config.get( FONT_SIZE ).options );
101
-
102
- return options.map( option => {
103
- const title = localizedTitles[ option.title ];
104
-
105
- if ( title && title != option.title ) {
106
- // Clone the option to avoid altering the original `namedPresets` from `./utils.js`.
107
- option = Object.assign( {}, option, { title } );
108
- }
109
-
110
- return option;
111
- } );
112
- }
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ static get pluginName() {
23
+ return 'FontSizeUI';
24
+ }
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ init() {
29
+ const editor = this.editor;
30
+ const t = editor.t;
31
+ const options = this._getLocalizedOptions();
32
+ const command = editor.commands.get(FONT_SIZE);
33
+ // Register UI component.
34
+ editor.ui.componentFactory.add(FONT_SIZE, locale => {
35
+ const dropdownView = createDropdown(locale);
36
+ addListToDropdown(dropdownView, () => _prepareListOptions(options, command));
37
+ // Create dropdown model.
38
+ dropdownView.buttonView.set({
39
+ label: t('Font Size'),
40
+ icon: fontSizeIcon,
41
+ tooltip: true
42
+ });
43
+ dropdownView.extendTemplate({
44
+ attributes: {
45
+ class: [
46
+ 'ck-font-size-dropdown'
47
+ ]
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.fontSize.options` but processed to account for
61
+ * editor localization, i.e. to display {@link module:font/fontconfig~FontSizeOption}
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 localizedTitles = {
71
+ Default: t('Default'),
72
+ Tiny: t('Tiny'),
73
+ Small: t('Small'),
74
+ Big: t('Big'),
75
+ Huge: t('Huge')
76
+ };
77
+ const options = normalizeOptions((editor.config.get(FONT_SIZE)).options);
78
+ return options.map(option => {
79
+ const title = localizedTitles[option.title];
80
+ if (title && title != option.title) {
81
+ // Clone the option to avoid altering the original `namedPresets` from `./utils.js`.
82
+ option = Object.assign({}, option, { title });
83
+ }
84
+ return option;
85
+ });
86
+ }
113
87
  }
114
-
115
- // Prepares FontSize dropdown items.
116
- // @private
117
- // @param {Array.<module:font/fontsize~FontSizeOption>} options
118
- // @param {module:font/fontsize/fontsizecommand~FontSizeCommand} command
119
- function _prepareListOptions( options, command ) {
120
- const itemDefinitions = new Collection();
121
-
122
- for ( const option of options ) {
123
- const def = {
124
- type: 'button',
125
- model: new Model( {
126
- commandName: FONT_SIZE,
127
- commandParam: option.model,
128
- label: option.title,
129
- class: 'ck-fontsize-option',
130
- withText: true
131
- } )
132
- };
133
-
134
- if ( option.view && option.view.styles ) {
135
- def.model.set( 'labelStyle', `font-size:${ option.view.styles[ 'font-size' ] }` );
136
- }
137
-
138
- if ( option.view && option.view.classes ) {
139
- def.model.set( 'class', `${ def.model.class } ${ option.view.classes }` );
140
- }
141
-
142
- def.model.bind( 'isOn' ).to( command, 'value', value => value === option.model );
143
-
144
- // Add the option to the collection.
145
- itemDefinitions.add( def );
146
- }
147
-
148
- return itemDefinitions;
88
+ /**
89
+ * Prepares FontSize dropdown items.
90
+ */
91
+ function _prepareListOptions(options, command) {
92
+ const itemDefinitions = new Collection();
93
+ for (const option of options) {
94
+ const def = {
95
+ type: 'button',
96
+ model: new Model({
97
+ commandName: FONT_SIZE,
98
+ commandParam: option.model,
99
+ label: option.title,
100
+ class: 'ck-fontsize-option',
101
+ withText: true
102
+ })
103
+ };
104
+ if (option.view && typeof option.view !== 'string') {
105
+ if (option.view.styles) {
106
+ def.model.set('labelStyle', `font-size:${option.view.styles['font-size']}`);
107
+ }
108
+ if (option.view.classes) {
109
+ def.model.set('class', `${def.model.class} ${option.view.classes}`);
110
+ }
111
+ }
112
+ def.model.bind('isOn').to(command, 'value', value => value === option.model);
113
+ // Add the option to the collection.
114
+ itemDefinitions.add(def);
115
+ }
116
+ return itemDefinitions;
149
117
  }
@@ -0,0 +1,12 @@
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 FontSizeOption } from '../fontconfig';
6
+ /**
7
+ * Normalizes and translates the {@link module:font/fontconfig~FontSizeConfig#options configuration options}
8
+ * to the {@link module:font/fontconfig~FontSizeOption} format.
9
+ *
10
+ * @param configuredOptions An array of options taken from the configuration.
11
+ */
12
+ export declare function normalizeOptions(configuredOptions: Array<string | number | FontSizeOption>): Array<FontSizeOption>;