@ckeditor/ckeditor5-font 36.0.1 → 37.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.
Files changed (56) hide show
  1. package/build/font.js +1 -1
  2. package/package.json +20 -15
  3. package/src/augmentation.d.ts +58 -0
  4. package/src/augmentation.js +5 -0
  5. package/src/documentcolorcollection.d.ts +70 -0
  6. package/src/documentcolorcollection.js +34 -63
  7. package/src/font.d.ts +29 -0
  8. package/src/font.js +12 -19
  9. package/src/fontbackgroundcolor/fontbackgroundcolorcommand.d.ts +26 -0
  10. package/src/fontbackgroundcolor/fontbackgroundcolorcommand.js +9 -15
  11. package/src/fontbackgroundcolor/fontbackgroundcolorediting.d.ts +26 -0
  12. package/src/fontbackgroundcolor/fontbackgroundcolorediting.js +103 -116
  13. package/src/fontbackgroundcolor/fontbackgroundcolorui.d.ts +22 -0
  14. package/src/fontbackgroundcolor/fontbackgroundcolorui.js +18 -25
  15. package/src/fontbackgroundcolor.d.ts +28 -0
  16. package/src/fontbackgroundcolor.js +12 -165
  17. package/src/fontcolor/fontcolorcommand.d.ts +25 -0
  18. package/src/fontcolor/fontcolorcommand.js +9 -15
  19. package/src/fontcolor/fontcolorediting.d.ts +26 -0
  20. package/src/fontcolor/fontcolorediting.js +115 -128
  21. package/src/fontcolor/fontcolorui.d.ts +22 -0
  22. package/src/fontcolor/fontcolorui.js +18 -25
  23. package/src/fontcolor.d.ts +24 -0
  24. package/src/fontcolor.js +12 -168
  25. package/src/fontcommand.d.ts +46 -0
  26. package/src/fontcommand.js +54 -78
  27. package/src/fontconfig.d.ts +367 -0
  28. package/src/fontconfig.js +5 -0
  29. package/src/fontfamily/fontfamilycommand.d.ts +25 -0
  30. package/src/fontfamily/fontfamilycommand.js +9 -15
  31. package/src/fontfamily/fontfamilyediting.d.ts +39 -0
  32. package/src/fontfamily/fontfamilyediting.js +95 -116
  33. package/src/fontfamily/fontfamilyui.d.ts +30 -0
  34. package/src/fontfamily/fontfamilyui.js +90 -122
  35. package/src/fontfamily/utils.d.ts +15 -0
  36. package/src/fontfamily/utils.js +66 -79
  37. package/src/fontfamily.d.ts +24 -0
  38. package/src/fontfamily.js +12 -112
  39. package/src/fontsize/fontsizecommand.d.ts +25 -0
  40. package/src/fontsize/fontsizecommand.js +9 -15
  41. package/src/fontsize/fontsizeediting.d.ts +44 -0
  42. package/src/fontsize/fontsizeediting.js +137 -169
  43. package/src/fontsize/fontsizeui.d.ts +31 -0
  44. package/src/fontsize/fontsizeui.js +98 -130
  45. package/src/fontsize/utils.d.ts +12 -0
  46. package/src/fontsize/utils.js +145 -174
  47. package/src/fontsize.d.ts +35 -0
  48. package/src/fontsize.js +21 -141
  49. package/src/index.d.ts +27 -0
  50. package/src/index.js +1 -2
  51. package/src/ui/colortableview.d.ts +167 -0
  52. package/src/ui/colortableview.js +242 -418
  53. package/src/ui/colorui.d.ts +63 -0
  54. package/src/ui/colorui.js +78 -132
  55. package/src/utils.d.ts +77 -0
  56. package/src/utils.js +42 -72
@@ -2,135 +2,114 @@
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/fontfamily/fontfamilyediting
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
-
12
9
  import FontFamilyCommand from './fontfamilycommand';
13
10
  import { normalizeOptions } from './utils';
14
11
  import { buildDefinition, FONT_FAMILY } from '../utils';
15
-
16
12
  /**
17
13
  * The font family editing feature.
18
14
  *
19
15
  * It introduces the {@link module:font/fontfamily/fontfamilycommand~FontFamilyCommand command} and
20
16
  * the `fontFamily` attribute in the {@link module:engine/model/model~Model model} which renders
21
17
  * in the {@link module:engine/view/view view} as an inline `<span>` element (`<span style="font-family: Arial">`),
22
- * depending on the {@link module:font/fontfamily~FontFamilyConfig configuration}.
23
- *
24
- * @extends module:core/plugin~Plugin
18
+ * depending on the {@link module:font/fontconfig~FontFamilyConfig configuration}.
25
19
  */
26
20
  export default class FontFamilyEditing extends Plugin {
27
- /**
28
- * @inheritDoc
29
- */
30
- static get pluginName() {
31
- return 'FontFamilyEditing';
32
- }
33
-
34
- /**
35
- * @inheritDoc
36
- */
37
- constructor( editor ) {
38
- super( editor );
39
-
40
- // Define default configuration using font families shortcuts.
41
- editor.config.define( FONT_FAMILY, {
42
- options: [
43
- 'default',
44
- 'Arial, Helvetica, sans-serif',
45
- 'Courier New, Courier, monospace',
46
- 'Georgia, serif',
47
- 'Lucida Sans Unicode, Lucida Grande, sans-serif',
48
- 'Tahoma, Geneva, sans-serif',
49
- 'Times New Roman, Times, serif',
50
- 'Trebuchet MS, Helvetica, sans-serif',
51
- 'Verdana, Geneva, sans-serif'
52
- ],
53
- supportAllValues: false
54
- } );
55
- }
56
-
57
- /**
58
- * @inheritDoc
59
- */
60
- init() {
61
- const editor = this.editor;
62
-
63
- // Allow fontFamily attribute on text nodes.
64
- editor.model.schema.extend( '$text', { allowAttributes: FONT_FAMILY } );
65
- editor.model.schema.setAttributeProperties( FONT_FAMILY, {
66
- isFormatting: true,
67
- copyOnEnter: true
68
- } );
69
-
70
- // Get configured font family options without "default" option.
71
- const options = normalizeOptions( editor.config.get( 'fontFamily.options' ) ).filter( item => item.model );
72
- const definition = buildDefinition( FONT_FAMILY, options );
73
-
74
- // Set-up the two-way conversion.
75
- if ( editor.config.get( 'fontFamily.supportAllValues' ) ) {
76
- this._prepareAnyValueConverters();
77
- this._prepareCompatibilityConverter();
78
- } else {
79
- editor.conversion.attributeToElement( definition );
80
- }
81
-
82
- editor.commands.add( FONT_FAMILY, new FontFamilyCommand( editor ) );
83
- }
84
-
85
- /**
86
- * These converters enable keeping any value found as `style="font-family: *"` as a value of an attribute on a text even
87
- * if it is not defined in the plugin configuration.
88
- *
89
- * @private
90
- */
91
- _prepareAnyValueConverters() {
92
- const editor = this.editor;
93
-
94
- editor.conversion.for( 'downcast' ).attributeToElement( {
95
- model: FONT_FAMILY,
96
- view: ( attributeValue, { writer } ) => {
97
- return writer.createAttributeElement( 'span', { style: 'font-family:' + attributeValue }, { priority: 7 } );
98
- }
99
- } );
100
-
101
- editor.conversion.for( 'upcast' ).elementToAttribute( {
102
- model: {
103
- key: FONT_FAMILY,
104
- value: viewElement => viewElement.getStyle( 'font-family' )
105
- },
106
- view: {
107
- name: 'span',
108
- styles: {
109
- 'font-family': /.*/
110
- }
111
- }
112
- } );
113
- }
114
-
115
- /**
116
- * Adds support for legacy `<font face="..">` formatting.
117
- *
118
- * @private
119
- */
120
- _prepareCompatibilityConverter() {
121
- const editor = this.editor;
122
-
123
- editor.conversion.for( 'upcast' ).elementToAttribute( {
124
- view: {
125
- name: 'font',
126
- attributes: {
127
- 'face': /.*/
128
- }
129
- },
130
- model: {
131
- key: FONT_FAMILY,
132
- value: viewElement => viewElement.getAttribute( 'face' )
133
- }
134
- } );
135
- }
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get pluginName() {
25
+ return 'FontFamilyEditing';
26
+ }
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ constructor(editor) {
31
+ super(editor);
32
+ // Define default configuration using font families shortcuts.
33
+ editor.config.define(FONT_FAMILY, {
34
+ options: [
35
+ 'default',
36
+ 'Arial, Helvetica, sans-serif',
37
+ 'Courier New, Courier, monospace',
38
+ 'Georgia, serif',
39
+ 'Lucida Sans Unicode, Lucida Grande, sans-serif',
40
+ 'Tahoma, Geneva, sans-serif',
41
+ 'Times New Roman, Times, serif',
42
+ 'Trebuchet MS, Helvetica, sans-serif',
43
+ 'Verdana, Geneva, sans-serif'
44
+ ],
45
+ supportAllValues: false
46
+ });
47
+ }
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ init() {
52
+ const editor = this.editor;
53
+ // Allow fontFamily attribute on text nodes.
54
+ editor.model.schema.extend('$text', { allowAttributes: FONT_FAMILY });
55
+ editor.model.schema.setAttributeProperties(FONT_FAMILY, {
56
+ isFormatting: true,
57
+ copyOnEnter: true
58
+ });
59
+ // Get configured font family options without "default" option.
60
+ const options = normalizeOptions(editor.config.get('fontFamily.options')).filter(item => item.model);
61
+ const definition = buildDefinition(FONT_FAMILY, options);
62
+ // Set-up the two-way conversion.
63
+ if (editor.config.get('fontFamily.supportAllValues')) {
64
+ this._prepareAnyValueConverters();
65
+ this._prepareCompatibilityConverter();
66
+ }
67
+ else {
68
+ editor.conversion.attributeToElement(definition);
69
+ }
70
+ editor.commands.add(FONT_FAMILY, new FontFamilyCommand(editor));
71
+ }
72
+ /**
73
+ * These converters enable keeping any value found as `style="font-family: *"` as a value of an attribute on a text even
74
+ * if it is not defined in the plugin configuration.
75
+ */
76
+ _prepareAnyValueConverters() {
77
+ const editor = this.editor;
78
+ editor.conversion.for('downcast').attributeToElement({
79
+ model: FONT_FAMILY,
80
+ view: (attributeValue, { writer }) => {
81
+ return writer.createAttributeElement('span', { style: 'font-family:' + attributeValue }, { priority: 7 });
82
+ }
83
+ });
84
+ editor.conversion.for('upcast').elementToAttribute({
85
+ model: {
86
+ key: FONT_FAMILY,
87
+ value: (viewElement) => viewElement.getStyle('font-family')
88
+ },
89
+ view: {
90
+ name: 'span',
91
+ styles: {
92
+ 'font-family': /.*/
93
+ }
94
+ }
95
+ });
96
+ }
97
+ /**
98
+ * Adds support for legacy `<font face="..">` formatting.
99
+ */
100
+ _prepareCompatibilityConverter() {
101
+ const editor = this.editor;
102
+ editor.conversion.for('upcast').elementToAttribute({
103
+ view: {
104
+ name: 'font',
105
+ attributes: {
106
+ 'face': /.*/
107
+ }
108
+ },
109
+ model: {
110
+ key: FONT_FAMILY,
111
+ value: (viewElement) => viewElement.getAttribute('face')
112
+ }
113
+ });
114
+ }
136
115
  }
@@ -0,0 +1,30 @@
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
+ /**
10
+ * The font family UI plugin. It introduces the `'fontFamily'` dropdown.
11
+ */
12
+ export default class FontFamilyUI extends Plugin {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get pluginName(): 'FontFamilyUI';
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ init(): void;
21
+ /**
22
+ * Returns options as defined in `config.fontFamily.options` but processed to account for
23
+ * editor localization, i.e. to display {@link module:font/fontconfig~FontFamilyOption}
24
+ * in the correct language.
25
+ *
26
+ * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
27
+ * when the user configuration is defined because the editor does not exist yet.
28
+ */
29
+ private _getLocalizedOptions;
30
+ }
@@ -2,140 +2,108 @@
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/fontfamily/fontfamilyui
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
9
  import { Collection } from 'ckeditor5/src/utils';
12
10
  import { Model, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
13
-
14
11
  import { normalizeOptions } from './utils';
15
12
  import { FONT_FAMILY } from '../utils';
16
-
17
13
  import fontFamilyIcon from '../../theme/icons/font-family.svg';
18
-
19
14
  /**
20
15
  * The font family UI plugin. It introduces the `'fontFamily'` dropdown.
21
- *
22
- * @extends module:core/plugin~Plugin
23
16
  */
24
17
  export default class FontFamilyUI extends Plugin {
25
- /**
26
- * @inheritDoc
27
- */
28
- static get pluginName() {
29
- return 'FontFamilyUI';
30
- }
31
-
32
- /**
33
- * @inheritDoc
34
- */
35
- init() {
36
- const editor = this.editor;
37
- const t = editor.t;
38
-
39
- const options = this._getLocalizedOptions();
40
-
41
- const command = editor.commands.get( FONT_FAMILY );
42
-
43
- // Register UI component.
44
- editor.ui.componentFactory.add( FONT_FAMILY, locale => {
45
- const dropdownView = createDropdown( locale );
46
-
47
- addListToDropdown( dropdownView, () => _prepareListOptions( options, command ) );
48
-
49
- dropdownView.buttonView.set( {
50
- label: t( 'Font Family' ),
51
- icon: fontFamilyIcon,
52
- tooltip: true
53
- } );
54
-
55
- dropdownView.extendTemplate( {
56
- attributes: {
57
- class: 'ck-font-family-dropdown'
58
- }
59
- } );
60
-
61
- dropdownView.bind( 'isEnabled' ).to( command );
62
-
63
- // Execute command when an item from the dropdown is selected.
64
- this.listenTo( dropdownView, 'execute', evt => {
65
- editor.execute( evt.source.commandName, { value: evt.source.commandParam } );
66
- editor.editing.view.focus();
67
- } );
68
-
69
- return dropdownView;
70
- } );
71
- }
72
-
73
- /**
74
- * Returns options as defined in `config.fontFamily.options` but processed to account for
75
- * editor localization, i.e. to display {@link module:font/fontfamily~FontFamilyOption}
76
- * in the correct language.
77
- *
78
- * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
79
- * when the user configuration is defined because the editor does not exist yet.
80
- *
81
- * @private
82
- * @returns {Array.<module:font/fontfamily~FontFamilyOption>}.
83
- */
84
- _getLocalizedOptions() {
85
- const editor = this.editor;
86
- const t = editor.t;
87
-
88
- const options = normalizeOptions( editor.config.get( FONT_FAMILY ).options );
89
-
90
- return options.map( option => {
91
- // The only title to localize is "Default" others are font names.
92
- if ( option.title === 'Default' ) {
93
- option.title = t( 'Default' );
94
- }
95
-
96
- return option;
97
- } );
98
- }
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
+ // Register UI component.
33
+ editor.ui.componentFactory.add(FONT_FAMILY, locale => {
34
+ const dropdownView = createDropdown(locale);
35
+ addListToDropdown(dropdownView, () => _prepareListOptions(options, command));
36
+ dropdownView.buttonView.set({
37
+ label: t('Font Family'),
38
+ icon: fontFamilyIcon,
39
+ tooltip: true
40
+ });
41
+ dropdownView.extendTemplate({
42
+ attributes: {
43
+ class: 'ck-font-family-dropdown'
44
+ }
45
+ });
46
+ dropdownView.bind('isEnabled').to(command);
47
+ // Execute command when an item from the dropdown is selected.
48
+ this.listenTo(dropdownView, 'execute', evt => {
49
+ editor.execute(evt.source.commandName, { value: evt.source.commandParam });
50
+ editor.editing.view.focus();
51
+ });
52
+ return dropdownView;
53
+ });
54
+ }
55
+ /**
56
+ * Returns options as defined in `config.fontFamily.options` but processed to account for
57
+ * editor localization, i.e. to display {@link module:font/fontconfig~FontFamilyOption}
58
+ * in the correct language.
59
+ *
60
+ * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
61
+ * when the user configuration is defined because the editor does not exist yet.
62
+ */
63
+ _getLocalizedOptions() {
64
+ const editor = this.editor;
65
+ const t = editor.t;
66
+ const options = normalizeOptions((editor.config.get(FONT_FAMILY)).options);
67
+ return options.map(option => {
68
+ // The only title to localize is "Default" others are font names.
69
+ if (option.title === 'Default') {
70
+ option.title = t('Default');
71
+ }
72
+ return option;
73
+ });
74
+ }
99
75
  }
100
-
101
- // Prepares FontFamily dropdown items.
102
- // @private
103
- // @param {Array.<module:font/fontsize~FontSizeOption>} options
104
- // @param {module:font/fontsize/fontsizecommand~FontSizeCommand} command
105
- function _prepareListOptions( options, command ) {
106
- const itemDefinitions = new Collection();
107
-
108
- // Create dropdown items.
109
- for ( const option of options ) {
110
- const def = {
111
- type: 'button',
112
- model: new Model( {
113
- commandName: FONT_FAMILY,
114
- commandParam: option.model,
115
- label: option.title,
116
- withText: true
117
- } )
118
- };
119
-
120
- def.model.bind( 'isOn' ).to( command, 'value', value => {
121
- // "Default" or check in strict font-family converters mode.
122
- if ( value === option.model ) {
123
- return true;
124
- }
125
-
126
- if ( !value || !option.model ) {
127
- return false;
128
- }
129
-
130
- return value.split( ',' )[ 0 ].replace( /'/g, '' ).toLowerCase() === option.model.toLowerCase();
131
- } );
132
-
133
- // Try to set a dropdown list item style.
134
- if ( option.view && option.view.styles ) {
135
- def.model.set( 'labelStyle', `font-family: ${ option.view.styles[ 'font-family' ] }` );
136
- }
137
-
138
- itemDefinitions.add( def );
139
- }
140
- return itemDefinitions;
76
+ /**
77
+ * Prepares FontFamily dropdown items.
78
+ */
79
+ function _prepareListOptions(options, command) {
80
+ const itemDefinitions = new Collection();
81
+ // Create dropdown items.
82
+ for (const option of options) {
83
+ const def = {
84
+ type: 'button',
85
+ model: new Model({
86
+ commandName: FONT_FAMILY,
87
+ commandParam: option.model,
88
+ label: option.title,
89
+ withText: true
90
+ })
91
+ };
92
+ def.model.bind('isOn').to(command, 'value', value => {
93
+ // "Default" or check in strict font-family converters mode.
94
+ if (value === option.model) {
95
+ return true;
96
+ }
97
+ if (!value || !option.model) {
98
+ return false;
99
+ }
100
+ return value.split(',')[0].replace(/'/g, '').toLowerCase() === option.model.toLowerCase();
101
+ });
102
+ // Try to set a dropdown list item style.
103
+ if (option.view && typeof option.view !== 'string' && option.view.styles) {
104
+ def.model.set('labelStyle', `font-family: ${option.view.styles['font-family']}`);
105
+ }
106
+ itemDefinitions.add(def);
107
+ }
108
+ return itemDefinitions;
141
109
  }
@@ -0,0 +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>;