@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,92 +2,79 @@
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/utils
8
7
  */
9
-
10
8
  /**
11
- * Normalizes the {@link module:font/fontfamily~FontFamilyConfig#options configuration options}
12
- * to the {@link module:font/fontfamily~FontFamilyOption} format.
9
+ * Normalizes the {@link module:font/fontconfig~FontFamilyConfig#options configuration options}
10
+ * to the {@link module:font/fontconfig~FontFamilyOption} format.
13
11
  *
14
- * @param {Array.<String|Object>} configuredOptions An array of options taken from the configuration.
15
- * @returns {Array.<module:font/fontfamily~FontFamilyOption>}
12
+ * @param configuredOptions An array of options taken from the configuration.
16
13
  */
17
- export function normalizeOptions( configuredOptions ) {
18
- // Convert options to objects.
19
- return configuredOptions
20
- .map( getOptionDefinition )
21
- // Filter out undefined values that `getOptionDefinition` might return.
22
- .filter( option => !!option );
14
+ export function normalizeOptions(configuredOptions) {
15
+ // Convert options to objects.
16
+ return configuredOptions
17
+ .map(getOptionDefinition)
18
+ // Filter out undefined values that `getOptionDefinition` might return.
19
+ .filter(option => option !== undefined);
23
20
  }
24
-
25
- // Returns an option definition either created from string shortcut.
26
- // If object is passed then this method will return it without alternating it. Returns undefined for item than cannot be parsed.
27
- //
28
- // @param {String|Object} option
29
- // @returns {undefined|module:font/fontfamily~FontFamilyOption}
30
- function getOptionDefinition( option ) {
31
- // Treat any object as full item definition provided by user in configuration.
32
- if ( typeof option === 'object' ) {
33
- return option;
34
- }
35
-
36
- // Handle 'default' string as a special case. It will be used to remove the fontFamily attribute.
37
- if ( option === 'default' ) {
38
- return {
39
- title: 'Default',
40
- model: undefined
41
- };
42
- }
43
-
44
- // Ignore values that we cannot parse to a definition.
45
- if ( typeof option !== 'string' ) {
46
- return;
47
- }
48
-
49
- // Return font family definition from font string.
50
- return generateFontPreset( option );
21
+ /**
22
+ * Returns an option definition either created from string shortcut.
23
+ * If object is passed then this method will return it without alternating it. Returns undefined for item than cannot be parsed.
24
+ *
25
+ */
26
+ function getOptionDefinition(option) {
27
+ // Treat any object as full item definition provided by user in configuration.
28
+ if (typeof option === 'object') {
29
+ return option;
30
+ }
31
+ // Handle 'default' string as a special case. It will be used to remove the fontFamily attribute.
32
+ if (option === 'default') {
33
+ return {
34
+ title: 'Default',
35
+ model: undefined
36
+ };
37
+ }
38
+ // Ignore values that we cannot parse to a definition.
39
+ if (typeof option !== 'string') {
40
+ return undefined;
41
+ }
42
+ // Return font family definition from font string.
43
+ return generateFontPreset(option);
51
44
  }
52
-
53
- // Creates a predefined preset for pixel size. It deconstructs font-family like string into full configuration option.
54
- // A font definition is passed as coma delimited set of font family names. Font names might be quoted.
55
- //
56
- // @param {String} A font definition form configuration.
57
- function generateFontPreset( fontDefinition ) {
58
- // Remove quotes from font names. They will be normalized later.
59
- const fontNames = fontDefinition.replace( /"|'/g, '' ).split( ',' );
60
-
61
- // The first matched font name will be used as dropdown list item title and as model value.
62
- const firstFontName = fontNames[ 0 ];
63
-
64
- // CSS-compatible font names.
65
- const cssFontNames = fontNames.map( normalizeFontNameForCSS ).join( ', ' );
66
-
67
- return {
68
- title: firstFontName,
69
- model: cssFontNames,
70
- view: {
71
- name: 'span',
72
- styles: {
73
- 'font-family': cssFontNames
74
- },
75
- priority: 7
76
- }
77
- };
45
+ /**
46
+ * Creates a predefined preset for pixel size. It deconstructs font-family like string into full configuration option.
47
+ * A font definition is passed as coma delimited set of font family names. Font names might be quoted.
48
+ *
49
+ * @param fontDefinition A font definition form configuration.
50
+ */
51
+ function generateFontPreset(fontDefinition) {
52
+ // Remove quotes from font names. They will be normalized later.
53
+ const fontNames = fontDefinition.replace(/"|'/g, '').split(',');
54
+ // The first matched font name will be used as dropdown list item title and as model value.
55
+ const firstFontName = fontNames[0];
56
+ // CSS-compatible font names.
57
+ const cssFontNames = fontNames.map(normalizeFontNameForCSS).join(', ');
58
+ return {
59
+ title: firstFontName,
60
+ model: cssFontNames,
61
+ view: {
62
+ name: 'span',
63
+ styles: {
64
+ 'font-family': cssFontNames
65
+ },
66
+ priority: 7
67
+ }
68
+ };
78
69
  }
79
-
80
- // Normalizes font name for the style attribute. It adds braces (') if font name contains spaces.
81
- //
82
- // @param {String} fontName
83
- // @returns {String}
84
- function normalizeFontNameForCSS( fontName ) {
85
- fontName = fontName.trim();
86
-
87
- // Compound font names should be quoted.
88
- if ( fontName.indexOf( ' ' ) > 0 ) {
89
- fontName = `'${ fontName }'`;
90
- }
91
-
92
- return fontName;
70
+ /**
71
+ * Normalizes font name for the style attribute. It adds braces (') if font name contains spaces.
72
+ */
73
+ function normalizeFontNameForCSS(fontName) {
74
+ fontName = fontName.trim();
75
+ // Compound font names should be quoted.
76
+ if (fontName.indexOf(' ') > 0) {
77
+ fontName = `'${fontName}'`;
78
+ }
79
+ return fontName;
93
80
  }
@@ -0,0 +1,29 @@
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 { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
6
+ /**
7
+ * The font family plugin.
8
+ *
9
+ * For a detailed overview, check the {@glink features/font font feature} documentatiom
10
+ * and the {@glink api/font package page}.
11
+ *
12
+ * This is a "glue" plugin which loads the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing} and
13
+ * {@link module:font/fontfamily/fontfamilyui~FontFamilyUI} features in the editor.
14
+ */
15
+ export default class FontFamily extends Plugin {
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get requires(): PluginDependencies;
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get pluginName(): 'FontFamily';
24
+ }
25
+ declare module '@ckeditor/ckeditor5-core' {
26
+ interface PluginsMap {
27
+ [FontFamily.pluginName]: FontFamily;
28
+ }
29
+ }
package/src/fontfamily.js CHANGED
@@ -2,15 +2,9 @@
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
- /**
7
- * @module font/fontfamily
8
- */
9
-
10
5
  import { Plugin } from 'ckeditor5/src/core';
11
6
  import FontFamilyEditing from './fontfamily/fontfamilyediting';
12
7
  import FontFamilyUI from './fontfamily/fontfamilyui';
13
-
14
8
  /**
15
9
  * The font family plugin.
16
10
  *
@@ -19,112 +13,18 @@ import FontFamilyUI from './fontfamily/fontfamilyui';
19
13
  *
20
14
  * This is a "glue" plugin which loads the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing} and
21
15
  * {@link module:font/fontfamily/fontfamilyui~FontFamilyUI} features in the editor.
22
- *
23
- * @extends module:core/plugin~Plugin
24
16
  */
25
17
  export default class FontFamily extends Plugin {
26
- /**
27
- * @inheritDoc
28
- */
29
- static get requires() {
30
- return [ FontFamilyEditing, FontFamilyUI ];
31
- }
32
-
33
- /**
34
- * @inheritDoc
35
- */
36
- static get pluginName() {
37
- return 'FontFamily';
38
- }
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get requires() {
22
+ return [FontFamilyEditing, FontFamilyUI];
23
+ }
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName() {
28
+ return 'FontFamily';
29
+ }
39
30
  }
40
-
41
- /**
42
- * The font family option descriptor.
43
- *
44
- * @typedef {Object} module:font/fontfamily~FontFamilyOption
45
- *
46
- * @property {String} title The user-readable title of the option.
47
- * @property {String} model The attribute's unique value in the model.
48
- * @property {module:engine/view/elementdefinition~ElementDefinition} view View element configuration.
49
- * @property {Array.<module:engine/view/elementdefinition~ElementDefinition>} [upcastAlso] An array with all matched elements that
50
- * the view-to-model conversion should also accept.
51
- */
52
-
53
- /**
54
- * The configuration of the font family feature.
55
- * It is introduced by the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing} feature.
56
- *
57
- * Read more in {@link module:font/fontfamily~FontFamilyConfig}.
58
- *
59
- * @member {module:font/fontfamily~FontFamilyConfig} module:core/editor/editorconfig~EditorConfig#fontFamily
60
- */
61
-
62
- /**
63
- * The configuration of the font family feature.
64
- * This option is used by the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing} feature.
65
- *
66
- * ClassicEditor
67
- * .create( {
68
- * fontFamily: ... // Font family feature configuration.
69
- * } )
70
- * .then( ... )
71
- * .catch( ... );
72
- *
73
- * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
74
- *
75
- * @interface module:font/fontfamily~FontFamilyConfig
76
- */
77
-
78
- /**
79
- * Available font family options defined as an array of strings. The default value is:
80
- *
81
- * const fontFamilyConfig = {
82
- * options: [
83
- * 'default',
84
- * 'Arial, Helvetica, sans-serif',
85
- * 'Courier New, Courier, monospace',
86
- * 'Georgia, serif',
87
- * 'Lucida Sans Unicode, Lucida Grande, sans-serif',
88
- * 'Tahoma, Geneva, sans-serif',
89
- * 'Times New Roman, Times, serif',
90
- * 'Trebuchet MS, Helvetica, sans-serif',
91
- * 'Verdana, Geneva, sans-serif'
92
- * ]
93
- * };
94
- *
95
- * which configures 8 font family options. Each option consists of one or more comma–separated font family names. The first font name is
96
- * used as the dropdown item description in the UI.
97
- *
98
- * **Note:** The family names that consist of spaces should not have quotes (as opposed to the CSS standard). The necessary quotes
99
- * will be added automatically in the view. For example, the `"Lucida Sans Unicode"` will render as follows:
100
- *
101
- * <span style="font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif">...</span>
102
- *
103
- * The "default" option removes the `fontFamily` attribute from the selection. In such case, the text will
104
- * be rendered in the view using the default font family defined in the styles of the web page.
105
- *
106
- * Font family can be applied using the command API. To do that, use the `fontFamily` command and pass the desired family as a `value`.
107
- * For example, the following code will apply the `fontFamily` attribute with the `'Arial'` `value` to the current selection:
108
- *
109
- * editor.execute( 'fontFamily', { value: 'Arial' } );
110
- *
111
- * Executing the `'fontFamily'` command without any value will remove the `fontFamily` attribute from the current selection.
112
- *
113
- * @member {Array.<String|module:font/fontfamily~FontFamilyOption>} module:font/fontfamily~FontFamilyConfig#options
114
- */
115
-
116
- /**
117
- * By default the plugin removes any `font-family` value that does not match the plugin's configuration. It means that if you paste content
118
- * with font families that the editor does not understand, the `font-family` attribute will be removed and the content will be displayed
119
- * with the default font.
120
- *
121
- * You can preserve pasted font family values by switching the `supportAllValues` option to `true`:
122
- *
123
- * const fontFamilyConfig = {
124
- * supportAllValues: true
125
- * };
126
- *
127
- * With this configuration font families not specified in the editor configuration will not be removed when pasting the content.
128
- *
129
- * @member {Boolean} module:font/fontfamily~FontFamilyConfig#supportAllValues
130
- */
@@ -0,0 +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/fontsizecommand
7
+ */
8
+ import type { Editor } from 'ckeditor5/src/core';
9
+ import FontCommand from '../fontcommand';
10
+ import { FONT_SIZE } from '../utils';
11
+ /**
12
+ * The font size command. It is used by {@link module:font/fontsize/fontsizeediting~FontSizeEditing}
13
+ * to apply the font size.
14
+ *
15
+ * ```ts
16
+ * editor.execute( 'fontSize', { value: 'small' } );
17
+ * ```
18
+ *
19
+ * **Note**: Executing the command without the value removes the attribute from the model.
20
+ */
21
+ export default class FontSizeCommand extends FontCommand {
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ constructor(editor: Editor);
26
+ }
27
+ declare module '@ckeditor/ckeditor5-core' {
28
+ interface CommandsMap {
29
+ [FONT_SIZE]: FontSizeCommand;
30
+ }
31
+ }
@@ -2,29 +2,23 @@
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
- /**
7
- * @module font/fontsize/fontsizecommand
8
- */
9
-
10
5
  import FontCommand from '../fontcommand';
11
6
  import { FONT_SIZE } from '../utils';
12
-
13
7
  /**
14
8
  * The font size command. It is used by {@link module:font/fontsize/fontsizeediting~FontSizeEditing}
15
9
  * to apply the font size.
16
10
  *
17
- * editor.execute( 'fontSize', { value: 'small' } );
11
+ * ```ts
12
+ * editor.execute( 'fontSize', { value: 'small' } );
13
+ * ```
18
14
  *
19
15
  * **Note**: Executing the command without the value removes the attribute from the model.
20
- *
21
- * @extends module:font/fontcommand~FontCommand
22
16
  */
23
17
  export default class FontSizeCommand extends FontCommand {
24
- /**
25
- * @inheritDoc
26
- */
27
- constructor( editor ) {
28
- super( editor, FONT_SIZE );
29
- }
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ constructor(editor) {
22
+ super(editor, FONT_SIZE);
23
+ }
30
24
  }
@@ -0,0 +1,50 @@
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
+ import '../fontconfig';
10
+ /**
11
+ * The font size editing feature.
12
+ *
13
+ * It introduces the {@link module:font/fontsize/fontsizecommand~FontSizeCommand command} and the `fontSize`
14
+ * attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
15
+ * as a `<span>` element with either:
16
+ * * a style attribute (`<span style="font-size:12px">...</span>`),
17
+ * * or a class attribute (`<span class="text-small">...</span>`)
18
+ *
19
+ * depending on the {@link module:font/fontconfig~FontSizeConfig configuration}.
20
+ */
21
+ export default class FontSizeEditing extends Plugin {
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get pluginName(): 'FontSizeEditing';
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ constructor(editor: Editor);
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ init(): void;
34
+ /**
35
+ * These converters enable keeping any value found as `style="font-size: *"` as a value of an attribute on a text even
36
+ * if it is not defined in the plugin configuration.
37
+ *
38
+ * @param definition Converter definition out of input data.
39
+ */
40
+ private _prepareAnyValueConverters;
41
+ /**
42
+ * Adds support for legacy `<font size="..">` formatting.
43
+ */
44
+ private _prepareCompatibilityConverter;
45
+ }
46
+ declare module '@ckeditor/ckeditor5-core' {
47
+ interface PluginsMap {
48
+ [FontSizeEditing.pluginName]: FontSizeEditing;
49
+ }
50
+ }