@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,146 +2,133 @@
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/fontcolor/fontcolorediting
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
9
  import FontColorCommand from './fontcolorcommand';
12
10
  import { FONT_COLOR, renderDowncastElement, renderUpcastAttribute } from '../utils';
13
-
14
11
  /**
15
12
  * The font color editing feature.
16
13
  *
17
14
  * It introduces the {@link module:font/fontcolor/fontcolorcommand~FontColorCommand command} and
18
15
  * the `fontColor` attribute in the {@link module:engine/model/model~Model model} which renders
19
16
  * in the {@link module:engine/view/view view} as a `<span>` element (`<span style="color: ...">`),
20
- * depending on the {@link module:font/fontcolor~FontColorConfig configuration}.
21
- *
22
- * @extends module:core/plugin~Plugin
17
+ * depending on the {@link module:font/fontconfig~FontColorConfig configuration}.
23
18
  */
24
19
  export default class FontColorEditing extends Plugin {
25
- /**
26
- * @inheritDoc
27
- */
28
- static get pluginName() {
29
- return 'FontColorEditing';
30
- }
31
-
32
- /**
33
- * @inheritDoc
34
- */
35
- constructor( editor ) {
36
- super( editor );
37
-
38
- editor.config.define( FONT_COLOR, {
39
- colors: [
40
- {
41
- color: 'hsl(0, 0%, 0%)',
42
- label: 'Black'
43
- },
44
- {
45
- color: 'hsl(0, 0%, 30%)',
46
- label: 'Dim grey'
47
- },
48
- {
49
- color: 'hsl(0, 0%, 60%)',
50
- label: 'Grey'
51
- },
52
- {
53
- color: 'hsl(0, 0%, 90%)',
54
- label: 'Light grey'
55
- },
56
- {
57
- color: 'hsl(0, 0%, 100%)',
58
- label: 'White',
59
- hasBorder: true
60
- },
61
- {
62
- color: 'hsl(0, 75%, 60%)',
63
- label: 'Red'
64
- },
65
- {
66
- color: 'hsl(30, 75%, 60%)',
67
- label: 'Orange'
68
- },
69
- {
70
- color: 'hsl(60, 75%, 60%)',
71
- label: 'Yellow'
72
- },
73
- {
74
- color: 'hsl(90, 75%, 60%)',
75
- label: 'Light green'
76
- },
77
- {
78
- color: 'hsl(120, 75%, 60%)',
79
- label: 'Green'
80
- },
81
- {
82
- color: 'hsl(150, 75%, 60%)',
83
- label: 'Aquamarine'
84
- },
85
- {
86
- color: 'hsl(180, 75%, 60%)',
87
- label: 'Turquoise'
88
- },
89
- {
90
- color: 'hsl(210, 75%, 60%)',
91
- label: 'Light blue'
92
- },
93
- {
94
- color: 'hsl(240, 75%, 60%)',
95
- label: 'Blue'
96
- },
97
- {
98
- color: 'hsl(270, 75%, 60%)',
99
- label: 'Purple'
100
- }
101
- ],
102
- columns: 5
103
- } );
104
-
105
- editor.conversion.for( 'upcast' ).elementToAttribute( {
106
- view: {
107
- name: 'span',
108
- styles: {
109
- 'color': /[\s\S]+/
110
- }
111
- },
112
- model: {
113
- key: FONT_COLOR,
114
- value: renderUpcastAttribute( 'color' )
115
- }
116
- } );
117
-
118
- // Support legacy `<font color="..">` formatting.
119
- editor.conversion.for( 'upcast' ).elementToAttribute( {
120
- view: {
121
- name: 'font',
122
- attributes: {
123
- 'color': /^#?\w+$/
124
- }
125
- },
126
- model: {
127
- key: FONT_COLOR,
128
- value: viewElement => viewElement.getAttribute( 'color' )
129
- }
130
- } );
131
-
132
- editor.conversion.for( 'downcast' ).attributeToElement( {
133
- model: FONT_COLOR,
134
- view: renderDowncastElement( 'color' )
135
- } );
136
-
137
- editor.commands.add( FONT_COLOR, new FontColorCommand( editor ) );
138
-
139
- // Allow the font color attribute on text nodes.
140
- editor.model.schema.extend( '$text', { allowAttributes: FONT_COLOR } );
141
-
142
- editor.model.schema.setAttributeProperties( FONT_COLOR, {
143
- isFormatting: true,
144
- copyOnEnter: true
145
- } );
146
- }
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get pluginName() {
24
+ return 'FontColorEditing';
25
+ }
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ constructor(editor) {
30
+ super(editor);
31
+ editor.config.define(FONT_COLOR, {
32
+ colors: [
33
+ {
34
+ color: 'hsl(0, 0%, 0%)',
35
+ label: 'Black'
36
+ },
37
+ {
38
+ color: 'hsl(0, 0%, 30%)',
39
+ label: 'Dim grey'
40
+ },
41
+ {
42
+ color: 'hsl(0, 0%, 60%)',
43
+ label: 'Grey'
44
+ },
45
+ {
46
+ color: 'hsl(0, 0%, 90%)',
47
+ label: 'Light grey'
48
+ },
49
+ {
50
+ color: 'hsl(0, 0%, 100%)',
51
+ label: 'White',
52
+ hasBorder: true
53
+ },
54
+ {
55
+ color: 'hsl(0, 75%, 60%)',
56
+ label: 'Red'
57
+ },
58
+ {
59
+ color: 'hsl(30, 75%, 60%)',
60
+ label: 'Orange'
61
+ },
62
+ {
63
+ color: 'hsl(60, 75%, 60%)',
64
+ label: 'Yellow'
65
+ },
66
+ {
67
+ color: 'hsl(90, 75%, 60%)',
68
+ label: 'Light green'
69
+ },
70
+ {
71
+ color: 'hsl(120, 75%, 60%)',
72
+ label: 'Green'
73
+ },
74
+ {
75
+ color: 'hsl(150, 75%, 60%)',
76
+ label: 'Aquamarine'
77
+ },
78
+ {
79
+ color: 'hsl(180, 75%, 60%)',
80
+ label: 'Turquoise'
81
+ },
82
+ {
83
+ color: 'hsl(210, 75%, 60%)',
84
+ label: 'Light blue'
85
+ },
86
+ {
87
+ color: 'hsl(240, 75%, 60%)',
88
+ label: 'Blue'
89
+ },
90
+ {
91
+ color: 'hsl(270, 75%, 60%)',
92
+ label: 'Purple'
93
+ }
94
+ ],
95
+ columns: 5
96
+ });
97
+ editor.conversion.for('upcast').elementToAttribute({
98
+ view: {
99
+ name: 'span',
100
+ styles: {
101
+ 'color': /[\s\S]+/
102
+ }
103
+ },
104
+ model: {
105
+ key: FONT_COLOR,
106
+ value: renderUpcastAttribute('color')
107
+ }
108
+ });
109
+ // Support legacy `<font color="..">` formatting.
110
+ editor.conversion.for('upcast').elementToAttribute({
111
+ view: {
112
+ name: 'font',
113
+ attributes: {
114
+ 'color': /^#?\w+$/
115
+ }
116
+ },
117
+ model: {
118
+ key: FONT_COLOR,
119
+ value: (viewElement) => viewElement.getAttribute('color')
120
+ }
121
+ });
122
+ editor.conversion.for('downcast').attributeToElement({
123
+ model: FONT_COLOR,
124
+ view: renderDowncastElement('color')
125
+ });
126
+ editor.commands.add(FONT_COLOR, new FontColorCommand(editor));
127
+ // Allow the font color attribute on text nodes.
128
+ editor.model.schema.extend('$text', { allowAttributes: FONT_COLOR });
129
+ editor.model.schema.setAttributeProperties(FONT_COLOR, {
130
+ isFormatting: true,
131
+ copyOnEnter: true
132
+ });
133
+ }
147
134
  }
@@ -0,0 +1,22 @@
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/fontcolor/fontcolorui
7
+ */
8
+ import ColorUI from '../ui/colorui';
9
+ import type { Editor } from 'ckeditor5/src/core';
10
+ /**
11
+ * The font color UI plugin. It introduces the `'fontColor'` dropdown.
12
+ */
13
+ export default class FontColorUI extends ColorUI {
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ constructor(editor: Editor);
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get pluginName(): 'FontColorUI';
22
+ }
@@ -2,39 +2,32 @@
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/fontcolor/fontcolorui
8
7
  */
9
-
10
8
  import ColorUI from '../ui/colorui';
11
9
  import { FONT_COLOR } from '../utils';
12
10
  import fontColorIcon from '../../theme/icons/font-color.svg';
13
-
14
11
  /**
15
12
  * The font color UI plugin. It introduces the `'fontColor'` dropdown.
16
- *
17
- * @extends module:core/plugin~Plugin
18
13
  */
19
14
  export default class FontColorUI extends ColorUI {
20
- /**
21
- * @inheritDoc
22
- */
23
- constructor( editor ) {
24
- const t = editor.locale.t;
25
-
26
- super( editor, {
27
- commandName: FONT_COLOR,
28
- componentName: FONT_COLOR,
29
- icon: fontColorIcon,
30
- dropdownLabel: t( 'Font Color' )
31
- } );
32
- }
33
-
34
- /**
35
- * @inheritDoc
36
- */
37
- static get pluginName() {
38
- return 'FontColorUI';
39
- }
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ constructor(editor) {
19
+ const t = editor.locale.t;
20
+ super(editor, {
21
+ commandName: FONT_COLOR,
22
+ componentName: FONT_COLOR,
23
+ icon: fontColorIcon,
24
+ dropdownLabel: t('Font Color')
25
+ });
26
+ }
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ static get pluginName() {
31
+ return 'FontColorUI';
32
+ }
40
33
  }
@@ -0,0 +1,24 @@
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 color plugin.
8
+ *
9
+ * For a detailed overview, check the {@glink features/font font feature} documentation
10
+ * and the {@glink api/font package page}.
11
+ *
12
+ * This is a "glue" plugin which loads the {@link module:font/fontcolor/fontcolorediting~FontColorEditing} and
13
+ * {@link module:font/fontcolor/fontcolorui~FontColorUI} features in the editor.
14
+ */
15
+ export default class FontColor extends Plugin {
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get requires(): PluginDependencies;
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get pluginName(): 'FontColor';
24
+ }
package/src/fontcolor.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/fontcolor
8
- */
9
-
10
5
  import { Plugin } from 'ckeditor5/src/core';
11
6
  import FontColorEditing from './fontcolor/fontcolorediting';
12
7
  import FontColorUI from './fontcolor/fontcolorui';
13
-
14
8
  /**
15
9
  * The font color plugin.
16
10
  *
@@ -19,168 +13,18 @@ import FontColorUI from './fontcolor/fontcolorui';
19
13
  *
20
14
  * This is a "glue" plugin which loads the {@link module:font/fontcolor/fontcolorediting~FontColorEditing} and
21
15
  * {@link module:font/fontcolor/fontcolorui~FontColorUI} features in the editor.
22
- *
23
- * @extends module:core/plugin~Plugin
24
16
  */
25
17
  export default class FontColor extends Plugin {
26
- /**
27
- * @inheritDoc
28
- */
29
- static get requires() {
30
- return [ FontColorEditing, FontColorUI ];
31
- }
32
-
33
- /**
34
- * @inheritDoc
35
- */
36
- static get pluginName() {
37
- return 'FontColor';
38
- }
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get requires() {
22
+ return [FontColorEditing, FontColorUI];
23
+ }
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName() {
28
+ return 'FontColor';
29
+ }
39
30
  }
40
-
41
- /**
42
- * The configuration of the font color feature.
43
- * It is introduced by the {@link module:font/fontcolor/fontcolorediting~FontColorEditing} feature.
44
- *
45
- * Read more in {@link module:font/fontcolor~FontColorConfig}.
46
- *
47
- * @member {module:font/fontcolor~FontColorConfig} module:core/editor/editorconfig~EditorConfig#fontColor
48
- */
49
-
50
- /**
51
- * The configuration of the font color feature.
52
- * This option is used by the {@link module:font/fontcolor/fontcolorediting~FontColorEditing} feature.
53
- *
54
- * ClassicEditor
55
- * .create( {
56
- * fontColor: ... // Font color feature configuration.
57
- * } )
58
- * .then( ... )
59
- * .catch( ... );
60
- *
61
- * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
62
- *
63
- * @interface module:font/fontcolor~FontColorConfig
64
- */
65
-
66
- /**
67
- * Available font colors defined as an array of strings or objects.
68
- *
69
- * The default value registers the following colors:
70
- *
71
- * const fontColorConfig = {
72
- * colors: [
73
- * {
74
- * color: 'hsl(0, 0%, 0%)',
75
- * label: 'Black'
76
- * },
77
- * {
78
- * color: 'hsl(0, 0%, 30%)',
79
- * label: 'Dim grey'
80
- * },
81
- * {
82
- * color: 'hsl(0, 0%, 60%)',
83
- * label: 'Grey'
84
- * },
85
- * {
86
- * color: 'hsl(0, 0%, 90%)',
87
- * label: 'Light grey'
88
- * },
89
- * {
90
- * color: 'hsl(0, 0%, 100%)',
91
- * label: 'White',
92
- * hasBorder: true
93
- * },
94
- * {
95
- * color: 'hsl(0, 75%, 60%)',
96
- * label: 'Red'
97
- * },
98
- * {
99
- * color: 'hsl(30, 75%, 60%)',
100
- * label: 'Orange'
101
- * },
102
- * {
103
- * color: 'hsl(60, 75%, 60%)',
104
- * label: 'Yellow'
105
- * },
106
- * {
107
- * color: 'hsl(90, 75%, 60%)',
108
- * label: 'Light green'
109
- * },
110
- * {
111
- * color: 'hsl(120, 75%, 60%)',
112
- * label: 'Green'
113
- * },
114
- * {
115
- * color: 'hsl(150, 75%, 60%)',
116
- * label: 'Aquamarine'
117
- * },
118
- * {
119
- * color: 'hsl(180, 75%, 60%)',
120
- * label: 'Turquoise'
121
- * },
122
- * {
123
- * color: 'hsl(210, 75%, 60%)',
124
- * label: 'Light blue'
125
- * },
126
- * {
127
- * color: 'hsl(240, 75%, 60%)',
128
- * label: 'Blue'
129
- * },
130
- * {
131
- * color: 'hsl(270, 75%, 60%)',
132
- * label: 'Purple'
133
- * }
134
- * ]
135
- * };
136
- *
137
- * **Note**: The colors are displayed in the `'fontColor'` dropdown.
138
- *
139
- * @member {Array.<String|Object>} module:font/fontcolor~FontColorConfig#colors
140
- */
141
-
142
- /**
143
- * Represents the number of columns in the font color dropdown.
144
- *
145
- * The default value is:
146
- *
147
- * const fontColorConfig = {
148
- * columns: 5
149
- * }
150
- *
151
- * @member {Number} module:font/fontcolor~FontColorConfig#columns
152
- */
153
-
154
- /**
155
- * Determines the maximum number of available document colors.
156
- * Setting it to `0` will disable the document colors feature.
157
- *
158
- * By default it equals to the {@link module:font/fontcolor~FontColorConfig#columns} value.
159
- *
160
- * Examples:
161
- *
162
- * // 1) Neither document colors nor columns are defined in the configuration.
163
- * // Document colors will equal 5,
164
- * // because the value will be inherited from columns,
165
- * // which has a predefined value of 5.
166
- * const fontColorConfig = {}
167
- *
168
- * // 2) Document colors will equal 8, because the value will be inherited from columns.
169
- * const fontColorConfig = {
170
- * columns: 8
171
- * }
172
- *
173
- * // 3) Document colors will equal 24, because it has its own value defined.
174
- * const fontColorConfig = {
175
- * columns: 8,
176
- * documentColors: 24
177
- * }
178
- *
179
- * // 4) The document colors feature will be disabled.
180
- * const fontColorConfig = {
181
- * columns: 8,
182
- * documentColors: 0
183
- * }
184
- *
185
- * @member {Number} module:font/fontcolor~FontColorConfig#documentColors
186
- */
@@ -0,0 +1,46 @@
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/fontcommand
7
+ */
8
+ import { Command, type Editor } from 'ckeditor5/src/core';
9
+ /**
10
+ * The base font command.
11
+ */
12
+ export default abstract class FontCommand extends Command {
13
+ /**
14
+ * When set, it reflects the {@link #attributeKey} value of the selection.
15
+ *
16
+ * @observable
17
+ * @readonly
18
+ */
19
+ value: string;
20
+ /**
21
+ * A model attribute on which this command operates.
22
+ */
23
+ readonly attributeKey: string;
24
+ /**
25
+ * Creates an instance of the command.
26
+ *
27
+ * @param editor Editor instance.
28
+ * @param attributeKey The name of a model attribute on which this command operates.
29
+ */
30
+ constructor(editor: Editor, attributeKey: string);
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ refresh(): void;
35
+ /**
36
+ * Executes the command. Applies the `value` of the {@link #attributeKey} to the selection.
37
+ * If no `value` is passed, it removes the attribute from the selection.
38
+ *
39
+ * @param options Options for the executed command.
40
+ * @param options.value The value to apply.
41
+ * @fires execute
42
+ */
43
+ execute(options?: {
44
+ value?: string;
45
+ }): void;
46
+ }