@ckeditor/ckeditor5-engine 30.0.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.
- package/LICENSE.md +17 -0
- package/README.md +30 -0
- package/package.json +70 -0
- package/src/controller/datacontroller.js +563 -0
- package/src/controller/editingcontroller.js +149 -0
- package/src/conversion/conversion.js +644 -0
- package/src/conversion/conversionhelpers.js +40 -0
- package/src/conversion/downcastdispatcher.js +914 -0
- package/src/conversion/downcasthelpers.js +1706 -0
- package/src/conversion/mapper.js +696 -0
- package/src/conversion/modelconsumable.js +329 -0
- package/src/conversion/upcastdispatcher.js +807 -0
- package/src/conversion/upcasthelpers.js +997 -0
- package/src/conversion/viewconsumable.js +623 -0
- package/src/dataprocessor/basichtmlwriter.js +32 -0
- package/src/dataprocessor/dataprocessor.jsdoc +64 -0
- package/src/dataprocessor/htmldataprocessor.js +159 -0
- package/src/dataprocessor/htmlwriter.js +22 -0
- package/src/dataprocessor/xmldataprocessor.js +161 -0
- package/src/dev-utils/model.js +482 -0
- package/src/dev-utils/operationreplayer.js +140 -0
- package/src/dev-utils/utils.js +103 -0
- package/src/dev-utils/view.js +1091 -0
- package/src/index.js +52 -0
- package/src/model/batch.js +82 -0
- package/src/model/differ.js +1282 -0
- package/src/model/document.js +483 -0
- package/src/model/documentfragment.js +390 -0
- package/src/model/documentselection.js +1261 -0
- package/src/model/element.js +438 -0
- package/src/model/history.js +138 -0
- package/src/model/item.jsdoc +14 -0
- package/src/model/liveposition.js +182 -0
- package/src/model/liverange.js +221 -0
- package/src/model/markercollection.js +553 -0
- package/src/model/model.js +934 -0
- package/src/model/node.js +507 -0
- package/src/model/nodelist.js +217 -0
- package/src/model/operation/attributeoperation.js +202 -0
- package/src/model/operation/detachoperation.js +103 -0
- package/src/model/operation/insertoperation.js +188 -0
- package/src/model/operation/markeroperation.js +154 -0
- package/src/model/operation/mergeoperation.js +216 -0
- package/src/model/operation/moveoperation.js +209 -0
- package/src/model/operation/nooperation.js +58 -0
- package/src/model/operation/operation.js +139 -0
- package/src/model/operation/operationfactory.js +49 -0
- package/src/model/operation/renameoperation.js +155 -0
- package/src/model/operation/rootattributeoperation.js +211 -0
- package/src/model/operation/splitoperation.js +254 -0
- package/src/model/operation/transform.js +2389 -0
- package/src/model/operation/utils.js +292 -0
- package/src/model/position.js +1164 -0
- package/src/model/range.js +1049 -0
- package/src/model/rootelement.js +111 -0
- package/src/model/schema.js +1851 -0
- package/src/model/selection.js +902 -0
- package/src/model/text.js +138 -0
- package/src/model/textproxy.js +279 -0
- package/src/model/treewalker.js +414 -0
- package/src/model/utils/autoparagraphing.js +77 -0
- package/src/model/utils/deletecontent.js +528 -0
- package/src/model/utils/getselectedcontent.js +150 -0
- package/src/model/utils/insertcontent.js +824 -0
- package/src/model/utils/modifyselection.js +229 -0
- package/src/model/utils/selection-post-fixer.js +297 -0
- package/src/model/writer.js +1574 -0
- package/src/view/attributeelement.js +274 -0
- package/src/view/containerelement.js +123 -0
- package/src/view/document.js +221 -0
- package/src/view/documentfragment.js +273 -0
- package/src/view/documentselection.js +387 -0
- package/src/view/domconverter.js +1437 -0
- package/src/view/downcastwriter.js +2121 -0
- package/src/view/editableelement.js +118 -0
- package/src/view/element.js +945 -0
- package/src/view/elementdefinition.jsdoc +59 -0
- package/src/view/emptyelement.js +119 -0
- package/src/view/filler.js +161 -0
- package/src/view/item.jsdoc +14 -0
- package/src/view/matcher.js +776 -0
- package/src/view/node.js +391 -0
- package/src/view/observer/arrowkeysobserver.js +58 -0
- package/src/view/observer/bubblingemittermixin.js +307 -0
- package/src/view/observer/bubblingeventinfo.js +71 -0
- package/src/view/observer/clickobserver.js +46 -0
- package/src/view/observer/compositionobserver.js +79 -0
- package/src/view/observer/domeventdata.js +82 -0
- package/src/view/observer/domeventobserver.js +99 -0
- package/src/view/observer/fakeselectionobserver.js +118 -0
- package/src/view/observer/focusobserver.js +106 -0
- package/src/view/observer/inputobserver.js +44 -0
- package/src/view/observer/keyobserver.js +83 -0
- package/src/view/observer/mouseobserver.js +56 -0
- package/src/view/observer/mutationobserver.js +345 -0
- package/src/view/observer/observer.js +118 -0
- package/src/view/observer/selectionobserver.js +242 -0
- package/src/view/placeholder.js +285 -0
- package/src/view/position.js +426 -0
- package/src/view/range.js +533 -0
- package/src/view/rawelement.js +148 -0
- package/src/view/renderer.js +1037 -0
- package/src/view/rooteditableelement.js +107 -0
- package/src/view/selection.js +718 -0
- package/src/view/styles/background.js +73 -0
- package/src/view/styles/border.js +362 -0
- package/src/view/styles/margin.js +41 -0
- package/src/view/styles/padding.js +40 -0
- package/src/view/styles/utils.js +277 -0
- package/src/view/stylesmap.js +938 -0
- package/src/view/text.js +147 -0
- package/src/view/textproxy.js +199 -0
- package/src/view/treewalker.js +496 -0
- package/src/view/uielement.js +238 -0
- package/src/view/upcastwriter.js +484 -0
- package/src/view/view.js +721 -0
- package/theme/placeholder.css +27 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module engine/view/styles/utils
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const HEX_COLOR_REGEXP = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
11
|
+
const RGB_COLOR_REGEXP = /^rgb\([ ]?([0-9]{1,3}[ %]?,[ ]?){2,3}[0-9]{1,3}[ %]?\)$/i;
|
|
12
|
+
const RGBA_COLOR_REGEXP = /^rgba\([ ]?([0-9]{1,3}[ %]?,[ ]?){3}(1|[0-9]+%|[0]?\.?[0-9]+)\)$/i;
|
|
13
|
+
const HSL_COLOR_REGEXP = /^hsl\([ ]?([0-9]{1,3}[ %]?[,]?[ ]*){3}(1|[0-9]+%|[0]?\.?[0-9]+)?\)$/i;
|
|
14
|
+
const HSLA_COLOR_REGEXP = /^hsla\([ ]?([0-9]{1,3}[ %]?,[ ]?){2,3}(1|[0-9]+%|[0]?\.?[0-9]+)\)$/i;
|
|
15
|
+
|
|
16
|
+
const COLOR_NAMES = new Set( [
|
|
17
|
+
// CSS Level 1
|
|
18
|
+
'black', 'silver', 'gray', 'white', 'maroon', 'red', 'purple', 'fuchsia',
|
|
19
|
+
'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua',
|
|
20
|
+
// CSS Level 2 (Revision 1)
|
|
21
|
+
'orange',
|
|
22
|
+
// CSS Color Module Level 3
|
|
23
|
+
'aliceblue', 'antiquewhite', 'aquamarine', 'azure', 'beige', 'bisque', 'blanchedalmond', 'blueviolet', 'brown',
|
|
24
|
+
'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan',
|
|
25
|
+
'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta',
|
|
26
|
+
'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue',
|
|
27
|
+
'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey',
|
|
28
|
+
'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod',
|
|
29
|
+
'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush',
|
|
30
|
+
'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray',
|
|
31
|
+
'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray',
|
|
32
|
+
'lightslategrey', 'lightsteelblue', 'lightyellow', 'limegreen', 'linen', 'magenta', 'mediumaquamarine',
|
|
33
|
+
'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen',
|
|
34
|
+
'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite',
|
|
35
|
+
'oldlace', 'olivedrab', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred',
|
|
36
|
+
'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon',
|
|
37
|
+
'sandybrown', 'seagreen', 'seashell', 'sienna', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow',
|
|
38
|
+
'springgreen', 'steelblue', 'tan', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'whitesmoke', 'yellowgreen',
|
|
39
|
+
// CSS Color Module Level 3 (System Colors)
|
|
40
|
+
'activeborder', 'activecaption', 'appworkspace', 'background', 'buttonface', 'buttonhighlight', 'buttonshadow',
|
|
41
|
+
'buttontext', 'captiontext', 'graytext', 'highlight', 'highlighttext', 'inactiveborder', 'inactivecaption',
|
|
42
|
+
'inactivecaptiontext', 'infobackground', 'infotext', 'menu', 'menutext', 'scrollbar', 'threeddarkshadow',
|
|
43
|
+
'threedface', 'threedhighlight', 'threedlightshadow', 'threedshadow', 'window', 'windowframe', 'windowtext',
|
|
44
|
+
// CSS Color Module Level 4
|
|
45
|
+
'rebeccapurple',
|
|
46
|
+
// Keywords
|
|
47
|
+
'currentcolor', 'transparent'
|
|
48
|
+
] );
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Checks if string contains [color](https://developer.mozilla.org/en-US/docs/Web/CSS/color) CSS value.
|
|
52
|
+
*
|
|
53
|
+
* isColor( '#f00' ); // true
|
|
54
|
+
* isColor( '#AA00BB33' ); // true
|
|
55
|
+
* isColor( 'rgb(0, 0, 250)' ); // true
|
|
56
|
+
* isColor( 'hsla(240, 100%, 50%, .7)' ); // true
|
|
57
|
+
* isColor( 'deepskyblue' ); // true
|
|
58
|
+
*
|
|
59
|
+
* **Note**: It does not support CSS Level 4 whitespace syntax, system colors and radius values for HSL colors.
|
|
60
|
+
*
|
|
61
|
+
* @param {String} string
|
|
62
|
+
* @returns {Boolean}
|
|
63
|
+
*/
|
|
64
|
+
export function isColor( string ) {
|
|
65
|
+
// As far as I was able to test checking some pre-conditions is faster than joining each test with ||.
|
|
66
|
+
if ( string.startsWith( '#' ) ) {
|
|
67
|
+
return HEX_COLOR_REGEXP.test( string );
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if ( string.startsWith( 'rgb' ) ) {
|
|
71
|
+
return RGB_COLOR_REGEXP.test( string ) || RGBA_COLOR_REGEXP.test( string );
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if ( string.startsWith( 'hsl' ) ) {
|
|
75
|
+
return HSL_COLOR_REGEXP.test( string ) || HSLA_COLOR_REGEXP.test( string );
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Array check > RegExp test.
|
|
79
|
+
return COLOR_NAMES.has( string.toLowerCase() );
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const lineStyleValues = [ 'none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset' ];
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Checks if string contains [line style](https://developer.mozilla.org/en-US/docs/Web/CSS/border-style) CSS value.
|
|
86
|
+
*
|
|
87
|
+
* @param {String} string
|
|
88
|
+
* @returns {Boolean}
|
|
89
|
+
*/
|
|
90
|
+
export function isLineStyle( string ) {
|
|
91
|
+
return lineStyleValues.includes( string );
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const lengthRegExp = /^([+-]?[0-9]*([.][0-9]+)?(px|cm|mm|in|pc|pt|ch|em|ex|rem|vh|vw|vmin|vmax)|0)$/;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Checks if string contains [length](https://developer.mozilla.org/en-US/docs/Web/CSS/length) CSS value.
|
|
98
|
+
*
|
|
99
|
+
* @param {String} string
|
|
100
|
+
* @returns {Boolean}
|
|
101
|
+
*/
|
|
102
|
+
export function isLength( string ) {
|
|
103
|
+
return lengthRegExp.test( string );
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const PERCENTAGE_VALUE_REGEXP = /^[+-]?[0-9]*([.][0-9]+)?%$/;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Checks if string contains [percentage](https://developer.mozilla.org/en-US/docs/Web/CSS/percentage) CSS value.
|
|
110
|
+
*
|
|
111
|
+
* @param {String} string
|
|
112
|
+
* @returns {Boolean}
|
|
113
|
+
*/
|
|
114
|
+
export function isPercentage( string ) {
|
|
115
|
+
return PERCENTAGE_VALUE_REGEXP.test( string );
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const repeatValues = [ 'repeat-x', 'repeat-y', 'repeat', 'space', 'round', 'no-repeat' ];
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Checks if string contains [background repeat](https://developer.mozilla.org/en-US/docs/Web/CSS/background-repeat) CSS value.
|
|
122
|
+
*
|
|
123
|
+
* @param {String} string
|
|
124
|
+
* @returns {Boolean}
|
|
125
|
+
*/
|
|
126
|
+
export function isRepeat( string ) {
|
|
127
|
+
return repeatValues.includes( string );
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const positionValues = [ 'center', 'top', 'bottom', 'left', 'right' ];
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Checks if string contains [background position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position) CSS value.
|
|
134
|
+
*
|
|
135
|
+
* @param {String} string
|
|
136
|
+
* @returns {Boolean}
|
|
137
|
+
*/
|
|
138
|
+
export function isPosition( string ) {
|
|
139
|
+
return positionValues.includes( string );
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const attachmentValues = [ 'fixed', 'scroll', 'local' ];
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Checks if string contains [background attachment](https://developer.mozilla.org/en-US/docs/Web/CSS/background-attachment) CSS value.
|
|
146
|
+
*
|
|
147
|
+
* @param {String} string
|
|
148
|
+
* @returns {Boolean}
|
|
149
|
+
*/
|
|
150
|
+
export function isAttachment( string ) {
|
|
151
|
+
return attachmentValues.includes( string );
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const urlRegExp = /^url\(/;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Checks if string contains [URL](https://developer.mozilla.org/en-US/docs/Web/CSS/url) CSS value.
|
|
158
|
+
*
|
|
159
|
+
* @param {String} string
|
|
160
|
+
* @returns {Boolean}
|
|
161
|
+
*/
|
|
162
|
+
export function isURL( string ) {
|
|
163
|
+
return urlRegExp.test( string );
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function getBoxSidesValues( value = '' ) {
|
|
167
|
+
if ( value === '' ) {
|
|
168
|
+
return { top: undefined, right: undefined, bottom: undefined, left: undefined };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const values = getShorthandValues( value );
|
|
172
|
+
|
|
173
|
+
const top = values[ 0 ];
|
|
174
|
+
const bottom = values[ 2 ] || top;
|
|
175
|
+
const right = values[ 1 ] || top;
|
|
176
|
+
const left = values[ 3 ] || right;
|
|
177
|
+
|
|
178
|
+
return { top, bottom, right, left };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Default reducer for CSS properties that concerns edges of a box
|
|
183
|
+
* [shorthand](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties) notations:
|
|
184
|
+
*
|
|
185
|
+
* stylesProcessor.setReducer( 'padding', getBoxSidesValueReducer( 'padding' ) );
|
|
186
|
+
*
|
|
187
|
+
* @param {String} styleShorthand
|
|
188
|
+
* @returns {Function}
|
|
189
|
+
*/
|
|
190
|
+
export function getBoxSidesValueReducer( styleShorthand ) {
|
|
191
|
+
return value => {
|
|
192
|
+
const { top, right, bottom, left } = value;
|
|
193
|
+
|
|
194
|
+
const reduced = [];
|
|
195
|
+
|
|
196
|
+
if ( ![ top, right, left, bottom ].every( value => !!value ) ) {
|
|
197
|
+
if ( top ) {
|
|
198
|
+
reduced.push( [ styleShorthand + '-top', top ] );
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if ( right ) {
|
|
202
|
+
reduced.push( [ styleShorthand + '-right', right ] );
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if ( bottom ) {
|
|
206
|
+
reduced.push( [ styleShorthand + '-bottom', bottom ] );
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if ( left ) {
|
|
210
|
+
reduced.push( [ styleShorthand + '-left', left ] );
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
reduced.push( [ styleShorthand, getBoxSidesShorthandValue( value ) ] );
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return reduced;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Returns a [shorthand](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties) notation
|
|
222
|
+
* of a CSS property value.
|
|
223
|
+
*
|
|
224
|
+
* getBoxSidesShorthandValue( { top: '1px', right: '1px', bottom: '2px', left: '1px' } );
|
|
225
|
+
* // will return '1px 1px 2px'
|
|
226
|
+
*
|
|
227
|
+
* @param {module:engine/view/stylesmap~BoxSides} styleShorthand
|
|
228
|
+
* @returns {String}
|
|
229
|
+
*/
|
|
230
|
+
export function getBoxSidesShorthandValue( { top, right, bottom, left } ) {
|
|
231
|
+
const out = [];
|
|
232
|
+
|
|
233
|
+
if ( left !== right ) {
|
|
234
|
+
out.push( top, right, bottom, left );
|
|
235
|
+
} else if ( bottom !== top ) {
|
|
236
|
+
out.push( top, right, bottom );
|
|
237
|
+
} else if ( right !== top ) {
|
|
238
|
+
out.push( top, right );
|
|
239
|
+
} else {
|
|
240
|
+
out.push( top );
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return out.join( ' ' );
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Creates a normalizer for a [shorthand](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties) 1-to-4 value.
|
|
248
|
+
*
|
|
249
|
+
* stylesProcessor.setNormalizer( 'margin', getPositionShorthandNormalizer( 'margin' ) );
|
|
250
|
+
*
|
|
251
|
+
* @param {String} shorthand
|
|
252
|
+
* @returns {Function}
|
|
253
|
+
*/
|
|
254
|
+
export function getPositionShorthandNormalizer( shorthand ) {
|
|
255
|
+
return value => {
|
|
256
|
+
return {
|
|
257
|
+
path: shorthand,
|
|
258
|
+
value: getBoxSidesValues( value )
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Parses parts of a 1-to-4 value notation - handles some CSS values with spaces (like RGB()).
|
|
265
|
+
*
|
|
266
|
+
* getShorthandValues( 'red blue RGB(0, 0, 0)');
|
|
267
|
+
* // will return [ 'red', 'blue', 'RGB(0, 0, 0)' ]
|
|
268
|
+
*
|
|
269
|
+
* @param {String} string
|
|
270
|
+
* @returns {Array.<String>}
|
|
271
|
+
*/
|
|
272
|
+
export function getShorthandValues( string ) {
|
|
273
|
+
return string
|
|
274
|
+
.replace( /, /g, ',' ) // Exclude comma from spaces evaluation as values are separated by spaces.
|
|
275
|
+
.split( ' ' )
|
|
276
|
+
.map( string => string.replace( /,/g, ', ' ) ); // Restore original notation.
|
|
277
|
+
}
|