@ckeditor/ckeditor5-font 36.0.1 → 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,135 +2,115 @@
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
-
12
+ import '../fontconfig';
16
13
  /**
17
14
  * The font family editing feature.
18
15
  *
19
16
  * It introduces the {@link module:font/fontfamily/fontfamilycommand~FontFamilyCommand command} and
20
17
  * the `fontFamily` attribute in the {@link module:engine/model/model~Model model} which renders
21
18
  * 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
19
+ * depending on the {@link module:font/fontconfig~FontFamilyConfig configuration}.
25
20
  */
26
21
  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
- }
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get pluginName() {
26
+ return 'FontFamilyEditing';
27
+ }
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ constructor(editor) {
32
+ super(editor);
33
+ // Define default configuration using font families shortcuts.
34
+ editor.config.define(FONT_FAMILY, {
35
+ options: [
36
+ 'default',
37
+ 'Arial, Helvetica, sans-serif',
38
+ 'Courier New, Courier, monospace',
39
+ 'Georgia, serif',
40
+ 'Lucida Sans Unicode, Lucida Grande, sans-serif',
41
+ 'Tahoma, Geneva, sans-serif',
42
+ 'Times New Roman, Times, serif',
43
+ 'Trebuchet MS, Helvetica, sans-serif',
44
+ 'Verdana, Geneva, sans-serif'
45
+ ],
46
+ supportAllValues: false
47
+ });
48
+ }
49
+ /**
50
+ * @inheritDoc
51
+ */
52
+ init() {
53
+ const editor = this.editor;
54
+ // Allow fontFamily attribute on text nodes.
55
+ editor.model.schema.extend('$text', { allowAttributes: FONT_FAMILY });
56
+ editor.model.schema.setAttributeProperties(FONT_FAMILY, {
57
+ isFormatting: true,
58
+ copyOnEnter: true
59
+ });
60
+ // Get configured font family options without "default" option.
61
+ const options = normalizeOptions(editor.config.get('fontFamily.options')).filter(item => item.model);
62
+ const definition = buildDefinition(FONT_FAMILY, options);
63
+ // Set-up the two-way conversion.
64
+ if (editor.config.get('fontFamily.supportAllValues')) {
65
+ this._prepareAnyValueConverters();
66
+ this._prepareCompatibilityConverter();
67
+ }
68
+ else {
69
+ editor.conversion.attributeToElement(definition);
70
+ }
71
+ editor.commands.add(FONT_FAMILY, new FontFamilyCommand(editor));
72
+ }
73
+ /**
74
+ * These converters enable keeping any value found as `style="font-family: *"` as a value of an attribute on a text even
75
+ * if it is not defined in the plugin configuration.
76
+ */
77
+ _prepareAnyValueConverters() {
78
+ const editor = this.editor;
79
+ editor.conversion.for('downcast').attributeToElement({
80
+ model: FONT_FAMILY,
81
+ view: (attributeValue, { writer }) => {
82
+ return writer.createAttributeElement('span', { style: 'font-family:' + attributeValue }, { priority: 7 });
83
+ }
84
+ });
85
+ editor.conversion.for('upcast').elementToAttribute({
86
+ model: {
87
+ key: FONT_FAMILY,
88
+ value: (viewElement) => viewElement.getStyle('font-family')
89
+ },
90
+ view: {
91
+ name: 'span',
92
+ styles: {
93
+ 'font-family': /.*/
94
+ }
95
+ }
96
+ });
97
+ }
98
+ /**
99
+ * Adds support for legacy `<font face="..">` formatting.
100
+ */
101
+ _prepareCompatibilityConverter() {
102
+ const editor = this.editor;
103
+ editor.conversion.for('upcast').elementToAttribute({
104
+ view: {
105
+ name: 'font',
106
+ attributes: {
107
+ 'face': /.*/
108
+ }
109
+ },
110
+ model: {
111
+ key: FONT_FAMILY,
112
+ value: (viewElement) => viewElement.getAttribute('face')
113
+ }
114
+ });
115
+ }
136
116
  }
@@ -0,0 +1,35 @@
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
+ }
31
+ declare module '@ckeditor/ckeditor5-core' {
32
+ interface PluginsMap {
33
+ [FontFamilyUI.pluginName]: FontFamilyUI;
34
+ }
35
+ }
@@ -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>;