@ckeditor/ckeditor5-engine 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.
- package/README.md +1 -1
- package/package.json +25 -24
- package/src/controller/datacontroller.d.ts +331 -0
- package/src/controller/datacontroller.js +72 -116
- package/src/controller/editingcontroller.d.ts +98 -0
- package/src/controller/editingcontroller.js +22 -46
- package/src/conversion/conversion.d.ts +476 -0
- package/src/conversion/conversion.js +328 -347
- package/src/conversion/conversionhelpers.d.ts +26 -0
- package/src/conversion/conversionhelpers.js +1 -5
- package/src/conversion/downcastdispatcher.d.ts +547 -0
- package/src/conversion/downcastdispatcher.js +74 -152
- package/src/conversion/downcasthelpers.d.ts +1226 -0
- package/src/conversion/downcasthelpers.js +843 -762
- package/src/conversion/mapper.d.ts +503 -0
- package/src/conversion/mapper.js +84 -99
- package/src/conversion/modelconsumable.d.ts +201 -0
- package/src/conversion/modelconsumable.js +96 -99
- package/src/conversion/upcastdispatcher.d.ts +492 -0
- package/src/conversion/upcastdispatcher.js +73 -100
- package/src/conversion/upcasthelpers.d.ts +499 -0
- package/src/conversion/upcasthelpers.js +406 -373
- package/src/conversion/viewconsumable.d.ts +369 -0
- package/src/conversion/viewconsumable.js +139 -173
- package/src/dataprocessor/basichtmlwriter.d.ts +18 -0
- package/src/dataprocessor/basichtmlwriter.js +0 -9
- package/src/dataprocessor/dataprocessor.d.ts +61 -0
- package/src/dataprocessor/htmldataprocessor.d.ts +76 -0
- package/src/dataprocessor/htmldataprocessor.js +6 -28
- package/src/dataprocessor/htmlwriter.d.ts +16 -0
- package/src/dataprocessor/xmldataprocessor.d.ts +90 -0
- package/src/dataprocessor/xmldataprocessor.js +8 -40
- package/src/dev-utils/model.d.ts +124 -0
- package/src/dev-utils/model.js +41 -38
- package/src/dev-utils/operationreplayer.d.ts +51 -0
- package/src/dev-utils/operationreplayer.js +6 -14
- package/src/dev-utils/utils.d.ts +37 -0
- package/src/dev-utils/utils.js +5 -18
- package/src/dev-utils/view.d.ts +319 -0
- package/src/dev-utils/view.js +205 -226
- package/src/index.d.ts +108 -0
- package/src/index.js +4 -0
- package/src/model/batch.d.ts +106 -0
- package/src/model/differ.d.ts +329 -0
- package/src/model/document.d.ts +246 -0
- package/src/model/document.js +1 -1
- package/src/model/documentfragment.d.ts +196 -0
- package/src/model/documentfragment.js +2 -2
- package/src/model/documentselection.d.ts +420 -0
- package/src/model/element.d.ts +165 -0
- package/src/model/history.d.ts +114 -0
- package/src/model/item.d.ts +14 -0
- package/src/model/liveposition.d.ts +77 -0
- package/src/model/liverange.d.ts +102 -0
- package/src/model/markercollection.d.ts +335 -0
- package/src/model/model.d.ts +885 -0
- package/src/model/model.js +59 -81
- package/src/model/node.d.ts +256 -0
- package/src/model/nodelist.d.ts +91 -0
- package/src/model/operation/attributeoperation.d.ts +98 -0
- package/src/model/operation/detachoperation.d.ts +55 -0
- package/src/model/operation/insertoperation.d.ts +85 -0
- package/src/model/operation/markeroperation.d.ts +86 -0
- package/src/model/operation/mergeoperation.d.ts +95 -0
- package/src/model/operation/mergeoperation.js +1 -1
- package/src/model/operation/moveoperation.d.ts +91 -0
- package/src/model/operation/nooperation.d.ts +33 -0
- package/src/model/operation/operation.d.ts +89 -0
- package/src/model/operation/operationfactory.d.ts +18 -0
- package/src/model/operation/renameoperation.d.ts +78 -0
- package/src/model/operation/rootattributeoperation.d.ts +97 -0
- package/src/model/operation/rootattributeoperation.js +1 -1
- package/src/model/operation/splitoperation.d.ts +104 -0
- package/src/model/operation/splitoperation.js +1 -1
- package/src/model/operation/transform.d.ts +100 -0
- package/src/model/operation/utils.d.ts +71 -0
- package/src/model/operation/utils.js +1 -1
- package/src/model/position.d.ts +539 -0
- package/src/model/position.js +1 -1
- package/src/model/range.d.ts +458 -0
- package/src/model/range.js +1 -1
- package/src/model/rootelement.d.ts +40 -0
- package/src/model/schema.d.ts +1176 -0
- package/src/model/schema.js +19 -19
- package/src/model/selection.d.ts +472 -0
- package/src/model/text.d.ts +66 -0
- package/src/model/text.js +0 -2
- package/src/model/textproxy.d.ts +144 -0
- package/src/model/treewalker.d.ts +186 -0
- package/src/model/treewalker.js +19 -10
- package/src/model/typecheckable.d.ts +285 -0
- package/src/model/utils/autoparagraphing.d.ts +37 -0
- package/src/model/utils/deletecontent.d.ts +58 -0
- package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
- package/src/model/utils/getselectedcontent.d.ts +30 -0
- package/src/model/utils/insertcontent.d.ts +46 -0
- package/src/model/utils/insertcontent.js +2 -12
- package/src/model/utils/insertobject.d.ts +44 -0
- package/src/model/utils/insertobject.js +3 -14
- package/src/model/utils/modifyselection.d.ts +48 -0
- package/src/model/utils/selection-post-fixer.d.ts +65 -0
- package/src/model/writer.d.ts +823 -0
- package/src/model/writer.js +6 -61
- package/src/view/attributeelement.d.ts +108 -0
- package/src/view/attributeelement.js +25 -69
- package/src/view/containerelement.d.ts +49 -0
- package/src/view/containerelement.js +10 -43
- package/src/view/datatransfer.d.ts +75 -0
- package/src/view/document.d.ts +184 -0
- package/src/view/document.js +15 -84
- package/src/view/documentfragment.d.ts +149 -0
- package/src/view/documentfragment.js +39 -81
- package/src/view/documentselection.d.ts +306 -0
- package/src/view/documentselection.js +42 -143
- package/src/view/domconverter.d.ts +650 -0
- package/src/view/domconverter.js +157 -283
- package/src/view/downcastwriter.d.ts +996 -0
- package/src/view/downcastwriter.js +259 -426
- package/src/view/editableelement.d.ts +52 -0
- package/src/view/editableelement.js +9 -49
- package/src/view/element.d.ts +468 -0
- package/src/view/element.js +150 -222
- package/src/view/elementdefinition.d.ts +87 -0
- package/src/view/emptyelement.d.ts +41 -0
- package/src/view/emptyelement.js +11 -44
- package/src/view/filler.d.ts +111 -0
- package/src/view/filler.js +24 -21
- package/src/view/item.d.ts +14 -0
- package/src/view/matcher.d.ts +486 -0
- package/src/view/matcher.js +247 -218
- package/src/view/node.d.ts +163 -0
- package/src/view/node.js +26 -100
- package/src/view/observer/arrowkeysobserver.d.ts +41 -0
- package/src/view/observer/arrowkeysobserver.js +0 -13
- package/src/view/observer/bubblingemittermixin.d.ts +166 -0
- package/src/view/observer/bubblingemittermixin.js +36 -25
- package/src/view/observer/bubblingeventinfo.d.ts +47 -0
- package/src/view/observer/bubblingeventinfo.js +3 -29
- package/src/view/observer/clickobserver.d.ts +43 -0
- package/src/view/observer/clickobserver.js +9 -19
- package/src/view/observer/compositionobserver.d.ts +82 -0
- package/src/view/observer/compositionobserver.js +13 -42
- package/src/view/observer/domeventdata.d.ts +50 -0
- package/src/view/observer/domeventdata.js +5 -30
- package/src/view/observer/domeventobserver.d.ts +69 -0
- package/src/view/observer/domeventobserver.js +19 -21
- package/src/view/observer/fakeselectionobserver.d.ts +43 -0
- package/src/view/observer/fakeselectionobserver.js +0 -16
- package/src/view/observer/focusobserver.d.ts +82 -0
- package/src/view/observer/focusobserver.js +14 -40
- package/src/view/observer/inputobserver.d.ts +86 -0
- package/src/view/observer/inputobserver.js +18 -64
- package/src/view/observer/keyobserver.d.ts +66 -0
- package/src/view/observer/keyobserver.js +8 -42
- package/src/view/observer/mouseobserver.d.ts +89 -0
- package/src/view/observer/mouseobserver.js +8 -28
- package/src/view/observer/mutationobserver.d.ts +82 -0
- package/src/view/observer/mutationobserver.js +7 -37
- package/src/view/observer/observer.d.ts +84 -0
- package/src/view/observer/observer.js +12 -25
- package/src/view/observer/selectionobserver.d.ts +144 -0
- package/src/view/observer/selectionobserver.js +17 -107
- package/src/view/observer/tabobserver.d.ts +42 -0
- package/src/view/observer/tabobserver.js +0 -14
- package/src/view/placeholder.d.ts +85 -0
- package/src/view/placeholder.js +26 -43
- package/src/view/position.d.ts +189 -0
- package/src/view/position.js +36 -83
- package/src/view/range.d.ts +279 -0
- package/src/view/range.js +79 -122
- package/src/view/rawelement.d.ts +73 -0
- package/src/view/rawelement.js +34 -48
- package/src/view/renderer.d.ts +265 -0
- package/src/view/renderer.js +105 -193
- package/src/view/rooteditableelement.d.ts +41 -0
- package/src/view/rooteditableelement.js +12 -40
- package/src/view/selection.d.ts +375 -0
- package/src/view/selection.js +79 -153
- package/src/view/styles/background.d.ts +33 -0
- package/src/view/styles/background.js +14 -12
- package/src/view/styles/border.d.ts +43 -0
- package/src/view/styles/border.js +58 -48
- package/src/view/styles/margin.d.ts +29 -0
- package/src/view/styles/margin.js +13 -11
- package/src/view/styles/padding.d.ts +29 -0
- package/src/view/styles/padding.js +13 -11
- package/src/view/styles/utils.d.ts +93 -0
- package/src/view/styles/utils.js +22 -48
- package/src/view/stylesmap.d.ts +675 -0
- package/src/view/stylesmap.js +249 -244
- package/src/view/text.d.ts +74 -0
- package/src/view/text.js +16 -46
- package/src/view/textproxy.d.ts +97 -0
- package/src/view/textproxy.js +10 -59
- package/src/view/treewalker.d.ts +195 -0
- package/src/view/treewalker.js +43 -106
- package/src/view/typecheckable.d.ts +448 -0
- package/src/view/uielement.d.ts +96 -0
- package/src/view/uielement.js +29 -63
- package/src/view/upcastwriter.d.ts +417 -0
- package/src/view/upcastwriter.js +86 -157
- package/src/view/view.d.ts +417 -0
- package/src/view/view.js +47 -175
|
@@ -6,7 +6,9 @@ import { getShorthandValues, getBoxSidesValueReducer, getBoxSidesValues, isLengt
|
|
|
6
6
|
/**
|
|
7
7
|
* Adds a border CSS styles processing rules.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* editor.data.addStyleProcessorRules( addBorderRules );
|
|
11
|
+
* ```
|
|
10
12
|
*
|
|
11
13
|
* This rules merges all [border](https://developer.mozilla.org/en-US/docs/Web/CSS/border) styles notation shorthands:
|
|
12
14
|
*
|
|
@@ -25,15 +27,15 @@ import { getShorthandValues, getBoxSidesValueReducer, getBoxSidesValues, isLengt
|
|
|
25
27
|
*
|
|
26
28
|
* The normalized model stores border values as:
|
|
27
29
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* const styles = {
|
|
32
|
+
* border: {
|
|
33
|
+
* color: { top, right, bottom, left },
|
|
34
|
+
* style: { top, right, bottom, left },
|
|
35
|
+
* width: { top, right, bottom, left },
|
|
36
|
+
* }
|
|
37
|
+
* };
|
|
38
|
+
* ```
|
|
37
39
|
*/
|
|
38
40
|
export function addBorderRules(stylesProcessor) {
|
|
39
41
|
stylesProcessor.setNormalizer('border', getBorderNormalizer());
|
|
@@ -197,32 +199,38 @@ function normalizeBorderShorthand(string) {
|
|
|
197
199
|
}
|
|
198
200
|
return result;
|
|
199
201
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
202
|
+
/**
|
|
203
|
+
* The border reducer factory.
|
|
204
|
+
*
|
|
205
|
+
* It tries to produce the most optimal output for the specified styles.
|
|
206
|
+
*
|
|
207
|
+
* For a border style:
|
|
208
|
+
*
|
|
209
|
+
* ```css
|
|
210
|
+
* style: {top: "solid", bottom: "solid", right: "solid", left: "solid"}
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* It will produce: `border-style: solid`.
|
|
214
|
+
* For a border style and color:
|
|
215
|
+
*
|
|
216
|
+
* ```css
|
|
217
|
+
* color: {top: "#ff0", bottom: "#ff0", right: "#ff0", left: "#ff0"}
|
|
218
|
+
* style: {top: "solid", bottom: "solid", right: "solid", left: "solid"}
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* It will produce: `border-color: #ff0; border-style: solid`.
|
|
222
|
+
* If all border parameters are specified:
|
|
223
|
+
*
|
|
224
|
+
* ```css
|
|
225
|
+
* color: {top: "#ff0", bottom: "#ff0", right: "#ff0", left: "#ff0"}
|
|
226
|
+
* style: {top: "solid", bottom: "solid", right: "solid", left: "solid"}
|
|
227
|
+
* width: {top: "2px", bottom: "2px", right: "2px", left: "2px"}
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* It will combine everything into a single property: `border: 2px solid #ff0`.
|
|
231
|
+
*
|
|
232
|
+
* The definitions are merged only if all border selectors have the same values.
|
|
233
|
+
*/
|
|
226
234
|
function getBorderReducer() {
|
|
227
235
|
return value => {
|
|
228
236
|
const topStyles = extractBorderPosition(value, 'top');
|
|
@@ -258,8 +266,9 @@ function getBorderReducer() {
|
|
|
258
266
|
...reduceBorderPosition(leftStyles, 'left')
|
|
259
267
|
];
|
|
260
268
|
};
|
|
261
|
-
|
|
262
|
-
|
|
269
|
+
/**
|
|
270
|
+
* @param styles The array of objects with `style`, `color`, `width` properties.
|
|
271
|
+
*/
|
|
263
272
|
function getReducedStyleValueForType(styles, type) {
|
|
264
273
|
return styles
|
|
265
274
|
.map(style => style[type])
|
|
@@ -269,16 +278,17 @@ function getBorderReducer() {
|
|
|
269
278
|
function getBorderPositionReducer(which) {
|
|
270
279
|
return value => reduceBorderPosition(value, which);
|
|
271
280
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
281
|
+
/**
|
|
282
|
+
* Returns an array with reduced border styles depending on the specified values.
|
|
283
|
+
*
|
|
284
|
+
* If all border properties (width, style, color) are specified, the returned selector will be
|
|
285
|
+
* merged into a group: `border-*: [width] [style] [color]`.
|
|
286
|
+
*
|
|
287
|
+
* Otherwise, the specific definitions will be returned: `border-(width|style|color)-*: [value]`.
|
|
288
|
+
*
|
|
289
|
+
* @param value Styles if defined.
|
|
290
|
+
* @param which The border position.
|
|
291
|
+
*/
|
|
282
292
|
function reduceBorderPosition(value, which) {
|
|
283
293
|
const borderTypes = [];
|
|
284
294
|
if (value && (value.width)) {
|
|
@@ -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
|
+
/**
|
|
6
|
+
* @module engine/view/styles/margin
|
|
7
|
+
*/
|
|
8
|
+
import type { StylesProcessor } from '../stylesmap';
|
|
9
|
+
/**
|
|
10
|
+
* Adds a margin CSS styles processing rules.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* editor.data.addStyleProcessorRules( addMarginRules );
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The normalized value is stored as:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const styles = {
|
|
20
|
+
* margin: {
|
|
21
|
+
* top,
|
|
22
|
+
* right,
|
|
23
|
+
* bottom,
|
|
24
|
+
* left
|
|
25
|
+
* }
|
|
26
|
+
* };
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function addMarginRules(stylesProcessor: StylesProcessor): void;
|
|
@@ -6,20 +6,22 @@ import { getPositionShorthandNormalizer, getBoxSidesValueReducer } from './utils
|
|
|
6
6
|
/**
|
|
7
7
|
* Adds a margin CSS styles processing rules.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* editor.data.addStyleProcessorRules( addMarginRules );
|
|
11
|
+
* ```
|
|
10
12
|
*
|
|
11
13
|
* The normalized value is stored as:
|
|
12
14
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const styles = {
|
|
17
|
+
* margin: {
|
|
18
|
+
* top,
|
|
19
|
+
* right,
|
|
20
|
+
* bottom,
|
|
21
|
+
* left
|
|
22
|
+
* }
|
|
23
|
+
* };
|
|
24
|
+
* ```
|
|
23
25
|
*/
|
|
24
26
|
export function addMarginRules(stylesProcessor) {
|
|
25
27
|
stylesProcessor.setNormalizer('margin', getPositionShorthandNormalizer('margin'));
|
|
@@ -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
|
+
/**
|
|
6
|
+
* @module engine/view/styles/padding
|
|
7
|
+
*/
|
|
8
|
+
import type { StylesProcessor } from '../stylesmap';
|
|
9
|
+
/**
|
|
10
|
+
* Adds a margin CSS styles processing rules.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* editor.data.addStyleProcessorRules( addPaddingRules );
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The normalized value is stored as:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const styles = {
|
|
20
|
+
* padding: {
|
|
21
|
+
* top,
|
|
22
|
+
* right,
|
|
23
|
+
* bottom,
|
|
24
|
+
* left
|
|
25
|
+
* }
|
|
26
|
+
* };
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function addPaddingRules(stylesProcessor: StylesProcessor): void;
|
|
@@ -6,20 +6,22 @@ import { getPositionShorthandNormalizer, getBoxSidesValueReducer } from './utils
|
|
|
6
6
|
/**
|
|
7
7
|
* Adds a margin CSS styles processing rules.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* editor.data.addStyleProcessorRules( addPaddingRules );
|
|
11
|
+
* ```
|
|
10
12
|
*
|
|
11
13
|
* The normalized value is stored as:
|
|
12
14
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const styles = {
|
|
17
|
+
* padding: {
|
|
18
|
+
* top,
|
|
19
|
+
* right,
|
|
20
|
+
* bottom,
|
|
21
|
+
* left
|
|
22
|
+
* }
|
|
23
|
+
* };
|
|
24
|
+
* ```
|
|
23
25
|
*/
|
|
24
26
|
export function addPaddingRules(stylesProcessor) {
|
|
25
27
|
stylesProcessor.setNormalizer('padding', getPositionShorthandNormalizer('padding'));
|
|
@@ -0,0 +1,93 @@
|
|
|
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 engine/view/styles/utils
|
|
7
|
+
*/
|
|
8
|
+
import type { BoxSides, PropertyDescriptor, StyleValue } from '../stylesmap';
|
|
9
|
+
/**
|
|
10
|
+
* Checks if string contains [color](https://developer.mozilla.org/en-US/docs/Web/CSS/color) CSS value.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* isColor( '#f00' ); // true
|
|
14
|
+
* isColor( '#AA00BB33' ); // true
|
|
15
|
+
* isColor( 'rgb(0, 0, 250)' ); // true
|
|
16
|
+
* isColor( 'hsla(240, 100%, 50%, .7)' ); // true
|
|
17
|
+
* isColor( 'deepskyblue' ); // true
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* **Note**: It does not support CSS Level 4 whitespace syntax, system colors and radius values for HSL colors.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isColor(string: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if string contains [line style](https://developer.mozilla.org/en-US/docs/Web/CSS/border-style) CSS value.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isLineStyle(string: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if string contains [length](https://developer.mozilla.org/en-US/docs/Web/CSS/length) CSS value.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isLength(string: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if string contains [percentage](https://developer.mozilla.org/en-US/docs/Web/CSS/percentage) CSS value.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isPercentage(string: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if string contains [background repeat](https://developer.mozilla.org/en-US/docs/Web/CSS/background-repeat) CSS value.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isRepeat(string: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if string contains [background position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position) CSS value.
|
|
41
|
+
*/
|
|
42
|
+
export declare function isPosition(string: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if string contains [background attachment](https://developer.mozilla.org/en-US/docs/Web/CSS/background-attachment) CSS value.
|
|
45
|
+
*/
|
|
46
|
+
export declare function isAttachment(string: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Checks if string contains [URL](https://developer.mozilla.org/en-US/docs/Web/CSS/url) CSS value.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isURL(string: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Parses box sides as individual values.
|
|
53
|
+
*/
|
|
54
|
+
export declare function getBoxSidesValues(value?: string): BoxSides;
|
|
55
|
+
/**
|
|
56
|
+
* Default reducer for CSS properties that concerns edges of a box
|
|
57
|
+
* [shorthand](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties) notations:
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* stylesProcessor.setReducer( 'padding', getBoxSidesValueReducer( 'padding' ) );
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function getBoxSidesValueReducer(styleShorthand: string): (value: StyleValue) => Array<PropertyDescriptor>;
|
|
64
|
+
/**
|
|
65
|
+
* Returns a [shorthand](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties) notation
|
|
66
|
+
* of a CSS property value.
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* getBoxSidesShorthandValue( { top: '1px', right: '1px', bottom: '2px', left: '1px' } );
|
|
70
|
+
* // will return '1px 1px 2px'
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function getBoxSidesShorthandValue({ top, right, bottom, left }: BoxSides): string;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a normalizer for a [shorthand](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties) 1-to-4 value.
|
|
76
|
+
*
|
|
77
|
+
* ```ts
|
|
78
|
+
* stylesProcessor.setNormalizer( 'margin', getPositionShorthandNormalizer( 'margin' ) );
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function getPositionShorthandNormalizer(shorthand: string): (value: string) => {
|
|
82
|
+
path: string;
|
|
83
|
+
value: BoxSides;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Parses parts of a 1-to-4 value notation - handles some CSS values with spaces (like RGB()).
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* getShorthandValues( 'red blue RGB(0, 0, 0)');
|
|
90
|
+
* // will return [ 'red', 'blue', 'RGB(0, 0, 0)' ]
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function getShorthandValues(string: string): Array<string>;
|
package/src/view/styles/utils.js
CHANGED
|
@@ -43,16 +43,15 @@ const COLOR_NAMES = new Set([
|
|
|
43
43
|
/**
|
|
44
44
|
* Checks if string contains [color](https://developer.mozilla.org/en-US/docs/Web/CSS/color) CSS value.
|
|
45
45
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* isColor( '#f00' ); // true
|
|
48
|
+
* isColor( '#AA00BB33' ); // true
|
|
49
|
+
* isColor( 'rgb(0, 0, 250)' ); // true
|
|
50
|
+
* isColor( 'hsla(240, 100%, 50%, .7)' ); // true
|
|
51
|
+
* isColor( 'deepskyblue' ); // true
|
|
52
|
+
* ```
|
|
51
53
|
*
|
|
52
54
|
* **Note**: It does not support CSS Level 4 whitespace syntax, system colors and radius values for HSL colors.
|
|
53
|
-
*
|
|
54
|
-
* @param {String} string
|
|
55
|
-
* @returns {Boolean}
|
|
56
55
|
*/
|
|
57
56
|
export function isColor(string) {
|
|
58
57
|
// As far as I was able to test checking some pre-conditions is faster than joining each test with ||.
|
|
@@ -71,9 +70,6 @@ export function isColor(string) {
|
|
|
71
70
|
const lineStyleValues = ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset'];
|
|
72
71
|
/**
|
|
73
72
|
* Checks if string contains [line style](https://developer.mozilla.org/en-US/docs/Web/CSS/border-style) CSS value.
|
|
74
|
-
*
|
|
75
|
-
* @param {String} string
|
|
76
|
-
* @returns {Boolean}
|
|
77
73
|
*/
|
|
78
74
|
export function isLineStyle(string) {
|
|
79
75
|
return lineStyleValues.includes(string);
|
|
@@ -81,9 +77,6 @@ export function isLineStyle(string) {
|
|
|
81
77
|
const lengthRegExp = /^([+-]?[0-9]*([.][0-9]+)?(px|cm|mm|in|pc|pt|ch|em|ex|rem|vh|vw|vmin|vmax)|0)$/;
|
|
82
78
|
/**
|
|
83
79
|
* Checks if string contains [length](https://developer.mozilla.org/en-US/docs/Web/CSS/length) CSS value.
|
|
84
|
-
*
|
|
85
|
-
* @param {String} string
|
|
86
|
-
* @returns {Boolean}
|
|
87
80
|
*/
|
|
88
81
|
export function isLength(string) {
|
|
89
82
|
return lengthRegExp.test(string);
|
|
@@ -91,9 +84,6 @@ export function isLength(string) {
|
|
|
91
84
|
const PERCENTAGE_VALUE_REGEXP = /^[+-]?[0-9]*([.][0-9]+)?%$/;
|
|
92
85
|
/**
|
|
93
86
|
* Checks if string contains [percentage](https://developer.mozilla.org/en-US/docs/Web/CSS/percentage) CSS value.
|
|
94
|
-
*
|
|
95
|
-
* @param {String} string
|
|
96
|
-
* @returns {Boolean}
|
|
97
87
|
*/
|
|
98
88
|
export function isPercentage(string) {
|
|
99
89
|
return PERCENTAGE_VALUE_REGEXP.test(string);
|
|
@@ -101,9 +91,6 @@ export function isPercentage(string) {
|
|
|
101
91
|
const repeatValues = ['repeat-x', 'repeat-y', 'repeat', 'space', 'round', 'no-repeat'];
|
|
102
92
|
/**
|
|
103
93
|
* Checks if string contains [background repeat](https://developer.mozilla.org/en-US/docs/Web/CSS/background-repeat) CSS value.
|
|
104
|
-
*
|
|
105
|
-
* @param {String} string
|
|
106
|
-
* @returns {Boolean}
|
|
107
94
|
*/
|
|
108
95
|
export function isRepeat(string) {
|
|
109
96
|
return repeatValues.includes(string);
|
|
@@ -111,9 +98,6 @@ export function isRepeat(string) {
|
|
|
111
98
|
const positionValues = ['center', 'top', 'bottom', 'left', 'right'];
|
|
112
99
|
/**
|
|
113
100
|
* Checks if string contains [background position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position) CSS value.
|
|
114
|
-
*
|
|
115
|
-
* @param {String} string
|
|
116
|
-
* @returns {Boolean}
|
|
117
101
|
*/
|
|
118
102
|
export function isPosition(string) {
|
|
119
103
|
return positionValues.includes(string);
|
|
@@ -121,9 +105,6 @@ export function isPosition(string) {
|
|
|
121
105
|
const attachmentValues = ['fixed', 'scroll', 'local'];
|
|
122
106
|
/**
|
|
123
107
|
* Checks if string contains [background attachment](https://developer.mozilla.org/en-US/docs/Web/CSS/background-attachment) CSS value.
|
|
124
|
-
*
|
|
125
|
-
* @param {String} string
|
|
126
|
-
* @returns {Boolean}
|
|
127
108
|
*/
|
|
128
109
|
export function isAttachment(string) {
|
|
129
110
|
return attachmentValues.includes(string);
|
|
@@ -131,15 +112,12 @@ export function isAttachment(string) {
|
|
|
131
112
|
const urlRegExp = /^url\(/;
|
|
132
113
|
/**
|
|
133
114
|
* Checks if string contains [URL](https://developer.mozilla.org/en-US/docs/Web/CSS/url) CSS value.
|
|
134
|
-
*
|
|
135
|
-
* @param {String} string
|
|
136
|
-
* @returns {Boolean}
|
|
137
115
|
*/
|
|
138
116
|
export function isURL(string) {
|
|
139
117
|
return urlRegExp.test(string);
|
|
140
118
|
}
|
|
141
119
|
/**
|
|
142
|
-
*
|
|
120
|
+
* Parses box sides as individual values.
|
|
143
121
|
*/
|
|
144
122
|
export function getBoxSidesValues(value = '') {
|
|
145
123
|
if (value === '') {
|
|
@@ -156,10 +134,9 @@ export function getBoxSidesValues(value = '') {
|
|
|
156
134
|
* Default reducer for CSS properties that concerns edges of a box
|
|
157
135
|
* [shorthand](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties) notations:
|
|
158
136
|
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* @returns {Function}
|
|
137
|
+
* ```ts
|
|
138
|
+
* stylesProcessor.setReducer( 'padding', getBoxSidesValueReducer( 'padding' ) );
|
|
139
|
+
* ```
|
|
163
140
|
*/
|
|
164
141
|
export function getBoxSidesValueReducer(styleShorthand) {
|
|
165
142
|
return (value) => {
|
|
@@ -189,11 +166,10 @@ export function getBoxSidesValueReducer(styleShorthand) {
|
|
|
189
166
|
* Returns a [shorthand](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties) notation
|
|
190
167
|
* of a CSS property value.
|
|
191
168
|
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* @returns {String}
|
|
169
|
+
* ```ts
|
|
170
|
+
* getBoxSidesShorthandValue( { top: '1px', right: '1px', bottom: '2px', left: '1px' } );
|
|
171
|
+
* // will return '1px 1px 2px'
|
|
172
|
+
* ```
|
|
197
173
|
*/
|
|
198
174
|
export function getBoxSidesShorthandValue({ top, right, bottom, left }) {
|
|
199
175
|
const out = [];
|
|
@@ -214,10 +190,9 @@ export function getBoxSidesShorthandValue({ top, right, bottom, left }) {
|
|
|
214
190
|
/**
|
|
215
191
|
* Creates a normalizer for a [shorthand](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties) 1-to-4 value.
|
|
216
192
|
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* @returns {Function}
|
|
193
|
+
* ```ts
|
|
194
|
+
* stylesProcessor.setNormalizer( 'margin', getPositionShorthandNormalizer( 'margin' ) );
|
|
195
|
+
* ```
|
|
221
196
|
*/
|
|
222
197
|
export function getPositionShorthandNormalizer(shorthand) {
|
|
223
198
|
return (value) => {
|
|
@@ -230,11 +205,10 @@ export function getPositionShorthandNormalizer(shorthand) {
|
|
|
230
205
|
/**
|
|
231
206
|
* Parses parts of a 1-to-4 value notation - handles some CSS values with spaces (like RGB()).
|
|
232
207
|
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
* @returns {Array.<String>}
|
|
208
|
+
* ```ts
|
|
209
|
+
* getShorthandValues( 'red blue RGB(0, 0, 0)');
|
|
210
|
+
* // will return [ 'red', 'blue', 'RGB(0, 0, 0)' ]
|
|
211
|
+
* ```
|
|
238
212
|
*/
|
|
239
213
|
export function getShorthandValues(string) {
|
|
240
214
|
return string
|