浏览代码

Rename StylesMap.setStyle() to setTo().

Maciej Gołaszewski 5 年之前
父节点
当前提交
6dcd853a40

+ 2 - 2
packages/ckeditor5-engine/src/view/element.js

@@ -115,7 +115,7 @@ export default class Element extends Node {
 
 		if ( this._attrs.has( 'style' ) ) {
 			// Remove style attribute and handle it by styles map.
-			this._styles.setStyle( this._attrs.get( 'style' ) );
+			this._styles.setTo( this._attrs.get( 'style' ) );
 
 			this._attrs.delete( 'style' );
 		}
@@ -643,7 +643,7 @@ export default class Element extends Node {
 		if ( key == 'class' ) {
 			parseClasses( this._classes, value );
 		} else if ( key == 'style' ) {
-			this._styles.setStyle( value );
+			this._styles.setTo( value );
 		} else {
 			this._attrs.set( key, value );
 		}

+ 7 - 9
packages/ckeditor5-engine/src/view/stylesmap.js

@@ -57,18 +57,16 @@ export default class StylesMap {
 	}
 
 	/**
-	 * Re-sets internal styles definition.
+	 * Set styles map to a new value.
 	 *
-	 * @param {String} styleString
+	 *		styles.setTo( 'border:1px solid blue;margin-top:1px;' );
+	 *
+	 * @param {String} inlineStyle
 	 */
-	setStyle( styleString ) {
+	setTo( inlineStyle ) {
 		this.clear();
 
-		const map = parseInlineStyles( styleString );
-
-		for ( const key of map.keys() ) {
-			const value = map.get( key );
-
+		for ( const [ key, value ] of Array.from( parseInlineStyles( inlineStyle ).entries() ) ) {
 			this._styleProcessor.toNormalizedForm( key, value, this._styles );
 		}
 	}
@@ -146,7 +144,7 @@ export default class StylesMap {
 	 * Returns a normalized style object or value.
 	 *
 	 *		const styles = new Styles();
-	 *		styles.setStyle( 'margin:1px 2px 3em;' );
+	 *		styles.setTo( 'margin:1px 2px 3em;' );
 	 *
 	 *		console.log( styles.getNormalized( 'margin' ) );
 	 *		// will log:

+ 4 - 4
packages/ckeditor5-engine/tests/view/styles/backgroundstyles.js

@@ -17,7 +17,7 @@ describe( 'Background styles normalization', () => {
 
 	it( 'should normalize background', () => {
 		// TODO: border-box given only for coverage test.
-		styles.setStyle( 'background:url("example.jpg") center #f00 repeat-y fixed border-box;' );
+		styles.setTo( 'background:url("example.jpg") center #f00 repeat-y fixed border-box;' );
 
 		expect( styles.getNormalized( 'background' ) ).to.deep.equal( {
 			attachment: 'fixed',
@@ -30,19 +30,19 @@ describe( 'Background styles normalization', () => {
 
 	// TODO: define what should happen with layers
 	it.skip( 'should normalize background with layers', () => {
-		styles.setStyle( 'background:url("test.jpg") repeat-y,#f00;' );
+		styles.setTo( 'background:url("test.jpg") repeat-y,#f00;' );
 
 		expect( styles.getNormalized( 'background' ) ).to.deep.equal( { color: '#f00' } );
 	} );
 
 	it( 'should normalize background-color', () => {
-		styles.setStyle( 'background-color:#f00;' );
+		styles.setTo( 'background-color:#f00;' );
 
 		expect( styles.getNormalized( 'background' ) ).to.deep.equal( { color: '#f00' } );
 	} );
 
 	it( 'should output inline background-color style', () => {
-		styles.setStyle( 'background:#f00;' );
+		styles.setTo( 'background:#f00;' );
 
 		expect( styles.getInlineStyle() ).to.equal( 'background-color:#f00;' );
 		expect( styles.getInlineProperty( 'background-color' ) ).to.equal( '#f00' );

+ 48 - 48
packages/ckeditor5-engine/tests/view/styles/borderstyles.js

@@ -16,7 +16,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should parse border shorthand', () => {
-		styles.setStyle( 'border:1px solid blue;' );
+		styles.setTo( 'border:1px solid blue;' );
 
 		expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 			color: { top: 'blue', right: 'blue', bottom: 'blue', left: 'blue' },
@@ -26,7 +26,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should parse border shorthand with only style', () => {
-		styles.setStyle( 'border:solid;' );
+		styles.setTo( 'border:solid;' );
 
 		expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 			color: { top: undefined, right: undefined, bottom: undefined, left: undefined },
@@ -36,7 +36,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should parse border shorthand with other shorthands', () => {
-		styles.setStyle( 'border:1px solid blue;border-left:#665511 dashed 2.7em;border-top:7px dotted #ccc;' );
+		styles.setTo( 'border:1px solid blue;border-left:#665511 dashed 2.7em;border-top:7px dotted #ccc;' );
 
 		expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 			color: { top: '#ccc', right: 'blue', bottom: 'blue', left: '#665511' },
@@ -46,7 +46,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should parse border longhand', () => {
-		styles.setStyle( 'border-color: #f00 #ba2;' +
+		styles.setTo( 'border-color: #f00 #ba2;' +
 			'border-style: solid;' +
 			'border-width: 1px;' +
 			'border-bottom-width: 2px;' +
@@ -60,7 +60,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should output inline shorthand rules #1', () => {
-		styles.setStyle( 'border:1px solid blue;' );
+		styles.setTo( 'border:1px solid blue;' );
 
 		expect( styles.getInlineStyle() ).to.equal(
 			'border-bottom:1px solid blue;' +
@@ -86,7 +86,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should output inline shorthand rules #2', () => {
-		styles.setStyle( 'border:1px solid blue;border-left:#665511 dashed 2.7em;border-top:7px dotted #ccc;' );
+		styles.setTo( 'border:1px solid blue;border-left:#665511 dashed 2.7em;border-top:7px dotted #ccc;' );
 
 		expect( styles.getInlineStyle() ).to.equal(
 			'border-bottom:1px solid blue;' +
@@ -102,7 +102,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should parse border + border-position(only color defined)', () => {
-		styles.setStyle( 'border:1px solid blue;border-left:#665511;' );
+		styles.setTo( 'border:1px solid blue;border-left:#665511;' );
 
 		expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 			color: { top: 'blue', right: 'blue', bottom: 'blue', left: '#665511' },
@@ -112,7 +112,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should parse border + border-position(only style defined)', () => {
-		styles.setStyle( 'border:1px solid blue;border-left:ridge;' );
+		styles.setTo( 'border:1px solid blue;border-left:ridge;' );
 
 		expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 			color: { top: 'blue', right: 'blue', bottom: 'blue', left: 'blue' },
@@ -122,7 +122,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should parse border + border-position(only width defined)', () => {
-		styles.setStyle( 'border:1px solid blue;border-left:1337px' );
+		styles.setTo( 'border:1px solid blue;border-left:1337px' );
 
 		expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 			color: { top: 'blue', right: 'blue', bottom: 'blue', left: 'blue' },
@@ -132,7 +132,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should merge rules on insert other shorthand', () => {
-		styles.setStyle( 'border:1px solid blue;' );
+		styles.setTo( 'border:1px solid blue;' );
 		styles.insertProperty( 'border-left', '#665511 dashed 2.7em' );
 		styles.insertProperty( 'border-top', '7px dotted #ccc' );
 
@@ -149,7 +149,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should output', () => {
-		styles.setStyle( 'border:1px solid blue;' );
+		styles.setTo( 'border:1px solid blue;' );
 		styles.removeProperty( 'border-color' );
 
 		expect( styles.getInlineStyle() ).to.equal(
@@ -170,7 +170,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should output border with only style shorthand (style)', () => {
-		styles.setStyle( 'border:solid;' );
+		styles.setTo( 'border:solid;' );
 
 		expect( styles.getInlineStyle() ).to.equal(
 			'border-bottom:solid;' +
@@ -189,7 +189,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should output border with only style shorthand (color)', () => {
-		styles.setStyle( 'border:#f00;' );
+		styles.setTo( 'border:#f00;' );
 
 		expect( styles.getInlineStyle() ).to.equal(
 			'border-bottom:#f00;' +
@@ -208,7 +208,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should output border with only style shorthand (width)', () => {
-		styles.setStyle( 'border:1px;' );
+		styles.setTo( 'border:1px;' );
 
 		expect( styles.getInlineStyle() ).to.equal(
 			'border-bottom:1px;' +
@@ -228,7 +228,7 @@ describe( 'Border styles normalization', () => {
 
 	describe( 'normalized values getters', () => {
 		it( 'should output border-*-color', () => {
-			styles.setStyle( 'border:1px solid #f00;' );
+			styles.setTo( 'border:1px solid #f00;' );
 
 			[ 'top', 'right', 'bottom', 'left' ].forEach( position => {
 				expect( styles.getNormalized( `border-${ position }-color` ) ).to.equal( '#f00' );
@@ -236,7 +236,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should output border-*-width', () => {
-			styles.setStyle( 'border:1px solid #f00;' );
+			styles.setTo( 'border:1px solid #f00;' );
 
 			[ 'top', 'right', 'bottom', 'left' ].forEach( position => {
 				expect( styles.getNormalized( `border-${ position }-width` ) ).to.equal( '1px' );
@@ -244,7 +244,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should output border-*-style', () => {
-			styles.setStyle( 'border:1px solid #f00;' );
+			styles.setTo( 'border:1px solid #f00;' );
 
 			[ 'top', 'right', 'bottom', 'left' ].forEach( position => {
 				expect( styles.getNormalized( `border-${ position }-style` ) ).to.equal( 'solid' );
@@ -254,25 +254,25 @@ describe( 'Border styles normalization', () => {
 
 	describe( 'border reducers', () => {
 		it( 'should output border-top', () => {
-			styles.setStyle( 'border:1px solid #f00' );
+			styles.setTo( 'border:1px solid #f00' );
 
 			expect( styles.getInlineProperty( 'border-top' ) ).to.equal( '1px solid #f00' );
 		} );
 
 		it( 'should output border-right', () => {
-			styles.setStyle( 'border:1px solid #f00' );
+			styles.setTo( 'border:1px solid #f00' );
 
 			expect( styles.getInlineProperty( 'border-right' ) ).to.equal( '1px solid #f00' );
 		} );
 
 		it( 'should output border-bottom', () => {
-			styles.setStyle( 'border:1px solid #f00' );
+			styles.setTo( 'border:1px solid #f00' );
 
 			expect( styles.getInlineProperty( 'border-bottom' ) ).to.equal( '1px solid #f00' );
 		} );
 
 		it( 'should output border-left', () => {
-			styles.setStyle( 'border:1px solid #f00' );
+			styles.setTo( 'border:1px solid #f00' );
 
 			expect( styles.getInlineProperty( 'border-left' ) ).to.equal( '1px solid #f00' );
 		} );
@@ -280,7 +280,7 @@ describe( 'Border styles normalization', () => {
 
 	describe( 'border-color', () => {
 		it( 'should set all border colors (1 value defined)', () => {
-			styles.setStyle( 'border-color:cyan;' );
+			styles.setTo( 'border-color:cyan;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				color: {
@@ -293,7 +293,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should set all border colors (2 values defined)', () => {
-			styles.setStyle( 'border-color:cyan magenta;' );
+			styles.setTo( 'border-color:cyan magenta;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				color: {
@@ -306,7 +306,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should set all border colors (3 values defined)', () => {
-			styles.setStyle( 'border-color:cyan magenta pink;' );
+			styles.setTo( 'border-color:cyan magenta pink;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				color: {
@@ -319,7 +319,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should set all border colors (4 values defined)', () => {
-			styles.setStyle( 'border-color:cyan magenta pink beige;' );
+			styles.setTo( 'border-color:cyan magenta pink beige;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				color: {
@@ -332,7 +332,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should merge with border shorthand', () => {
-			styles.setStyle( 'border:1px solid blue;border-color:cyan black;' );
+			styles.setTo( 'border:1px solid blue;border-color:cyan black;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				color: { top: 'cyan', right: 'black', bottom: 'cyan', left: 'black' },
@@ -342,7 +342,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should parse #RGB color value', () => {
-			styles.setStyle( 'border:#f00;' );
+			styles.setTo( 'border:#f00;' );
 
 			expect( styles.getNormalized( 'border-color' ) ).to.deep.equal( {
 				top: '#f00',
@@ -353,7 +353,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should parse #RGBA color value', () => {
-			styles.setStyle( 'border:#f00A;' );
+			styles.setTo( 'border:#f00A;' );
 
 			expect( styles.getNormalized( 'border-color' ) ).to.deep.equal( {
 				top: '#f00A',
@@ -364,7 +364,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should parse rgb() color value', () => {
-			styles.setStyle( 'border:rgb(0, 30%,35);' );
+			styles.setTo( 'border:rgb(0, 30%,35);' );
 
 			expect( styles.getNormalized( 'border-color' ) ).to.deep.equal( {
 				top: 'rgb(0, 30%, 35)',
@@ -375,7 +375,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should parse hsl() color value', () => {
-			styles.setStyle( 'border:hsl(0, 100%, 50%);' );
+			styles.setTo( 'border:hsl(0, 100%, 50%);' );
 
 			expect( styles.getNormalized( 'border-color' ) ).to.deep.equal( {
 				top: 'hsl(0, 100%, 50%)',
@@ -388,7 +388,7 @@ describe( 'Border styles normalization', () => {
 
 	describe( 'border-style', () => {
 		it( 'should set all border styles (1 value defined)', () => {
-			styles.setStyle( 'border-style:solid;' );
+			styles.setTo( 'border-style:solid;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				style: {
@@ -401,7 +401,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should set all border styles (2 values defined)', () => {
-			styles.setStyle( 'border-style:solid dotted;' );
+			styles.setTo( 'border-style:solid dotted;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				style: {
@@ -414,7 +414,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should set all border styles (3 values defined)', () => {
-			styles.setStyle( 'border-style:solid dotted dashed;' );
+			styles.setTo( 'border-style:solid dotted dashed;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				style: {
@@ -427,7 +427,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should set all border styles (4 values defined)', () => {
-			styles.setStyle( 'border-style:solid dotted dashed ridge;' );
+			styles.setTo( 'border-style:solid dotted dashed ridge;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				style: {
@@ -440,7 +440,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should parse none value', () => {
-			styles.setStyle( 'border:none;' );
+			styles.setTo( 'border:none;' );
 
 			expect( styles.getNormalized( 'border-style' ) ).to.deep.equal( {
 				top: 'none',
@@ -451,7 +451,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should parse line-style value', () => {
-			styles.setStyle( 'border:solid;' );
+			styles.setTo( 'border:solid;' );
 
 			expect( styles.getNormalized( 'border-style' ) ).to.deep.equal( {
 				top: 'solid',
@@ -462,7 +462,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should not parse non line-style value', () => {
-			styles.setStyle( 'border:blue' );
+			styles.setTo( 'border:blue' );
 
 			expect( styles.getNormalized( 'border-style' ) ).to.deep.equal( {
 				top: undefined,
@@ -475,7 +475,7 @@ describe( 'Border styles normalization', () => {
 
 	describe( 'border-width', () => {
 		it( 'should set all border widths (1 value defined)', () => {
-			styles.setStyle( 'border-width:1px;' );
+			styles.setTo( 'border-width:1px;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				width: {
@@ -488,7 +488,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should set all border widths (2 values defined)', () => {
-			styles.setStyle( 'border-width:1px .34cm;' );
+			styles.setTo( 'border-width:1px .34cm;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				width: {
@@ -501,7 +501,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should set all border widths (3 values defined)', () => {
-			styles.setStyle( 'border-width:1px .34cm 90.1rem;' );
+			styles.setTo( 'border-width:1px .34cm 90.1rem;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				width: {
@@ -514,7 +514,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should set all border widths (4 values defined)', () => {
-			styles.setStyle( 'border-width:1px .34cm 90.1rem thick;' );
+			styles.setTo( 'border-width:1px .34cm 90.1rem thick;' );
 
 			expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 				width: {
@@ -527,7 +527,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should parse px value', () => {
-			styles.setStyle( 'border:1px;' );
+			styles.setTo( 'border:1px;' );
 
 			expect( styles.getNormalized( 'border-width' ) ).to.deep.equal( {
 				top: '1px',
@@ -538,7 +538,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should parse em value', () => {
-			styles.setStyle( 'border:1em;' );
+			styles.setTo( 'border:1em;' );
 
 			expect( styles.getNormalized( 'border-width' ) ).to.deep.equal( {
 				top: '1em',
@@ -549,7 +549,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should parse thin value', () => {
-			styles.setStyle( 'border:thin' );
+			styles.setTo( 'border:thin' );
 
 			expect( styles.getNormalized( 'border-width' ) ).to.deep.equal( {
 				top: 'thin',
@@ -560,7 +560,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should parse medium value', () => {
-			styles.setStyle( 'border:medium' );
+			styles.setTo( 'border:medium' );
 
 			expect( styles.getNormalized( 'border-width' ) ).to.deep.equal( {
 				top: 'medium',
@@ -571,7 +571,7 @@ describe( 'Border styles normalization', () => {
 		} );
 
 		it( 'should parse thick value', () => {
-			styles.setStyle( 'border:thick' );
+			styles.setTo( 'border:thick' );
 
 			expect( styles.getNormalized( 'border-width' ) ).to.deep.equal( {
 				top: 'thick',
@@ -584,7 +584,7 @@ describe( 'Border styles normalization', () => {
 
 	describe( 'border-* position', () => {
 		it( 'should output all positions', () => {
-			styles.setStyle(
+			styles.setTo(
 				'border-top:none;' +
 				'border-left:none;' +
 				'border-bottom:dotted #FFC000 3.0pt;' +
@@ -606,7 +606,7 @@ describe( 'Border styles normalization', () => {
 
 	describe( 'getStyleNames() - border', () => {
 		it( 'should set all border colors (1 value defined)', () => {
-			styles.setStyle( 'border-color: deeppink deepskyblue;' +
+			styles.setTo( 'border-color: deeppink deepskyblue;' +
 				'border-style: solid;' +
 				'border-width: 1px;' +
 				'border-bottom-width: 2px;' +

+ 16 - 16
packages/ckeditor5-engine/tests/view/styles/marginstyles.js

@@ -16,7 +16,7 @@ describe( 'Margin styles normalizer', () => {
 	} );
 
 	it( 'should set all margins (1 value defined)', () => {
-		styles.setStyle( 'margin:1px;' );
+		styles.setTo( 'margin:1px;' );
 
 		expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
 			top: '1px',
@@ -27,7 +27,7 @@ describe( 'Margin styles normalizer', () => {
 	} );
 
 	it( 'should set all margins (2 values defined)', () => {
-		styles.setStyle( 'margin:1px .34cm;' );
+		styles.setTo( 'margin:1px .34cm;' );
 
 		expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
 			top: '1px',
@@ -38,7 +38,7 @@ describe( 'Margin styles normalizer', () => {
 	} );
 
 	it( 'should set all margins (3 values defined)', () => {
-		styles.setStyle( 'margin:1px .34cm 90.1rem;' );
+		styles.setTo( 'margin:1px .34cm 90.1rem;' );
 
 		expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
 			top: '1px',
@@ -49,7 +49,7 @@ describe( 'Margin styles normalizer', () => {
 	} );
 
 	it( 'should set all margins (4 values defined)', () => {
-		styles.setStyle( 'margin:1px .34cm 90.1rem thick;' );
+		styles.setTo( 'margin:1px .34cm 90.1rem thick;' );
 
 		expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
 			top: '1px',
@@ -60,7 +60,7 @@ describe( 'Margin styles normalizer', () => {
 	} );
 
 	it( 'should output inline style (1 value defined)', () => {
-		styles.setStyle( 'margin:1px;' );
+		styles.setTo( 'margin:1px;' );
 
 		expect( styles.getInlineStyle() ).to.equal( 'margin:1px;' );
 		expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px' );
@@ -71,7 +71,7 @@ describe( 'Margin styles normalizer', () => {
 	} );
 
 	it( 'should output inline style (2 values defined)', () => {
-		styles.setStyle( 'margin:1px .34cm;' );
+		styles.setTo( 'margin:1px .34cm;' );
 
 		expect( styles.getInlineStyle() ).to.equal( 'margin:1px .34cm;' );
 		expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px .34cm' );
@@ -82,7 +82,7 @@ describe( 'Margin styles normalizer', () => {
 	} );
 
 	it( 'should output inline style (3 values defined)', () => {
-		styles.setStyle( 'margin:1px .34cm 90.1rem;' );
+		styles.setTo( 'margin:1px .34cm 90.1rem;' );
 
 		expect( styles.getInlineStyle() ).to.equal( 'margin:1px .34cm 90.1rem;' );
 		expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px .34cm 90.1rem' );
@@ -93,7 +93,7 @@ describe( 'Margin styles normalizer', () => {
 	} );
 
 	it( 'should output inline style (3 values defined, only last different)', () => {
-		styles.setStyle( 'margin:1px 1px 90.1rem;' );
+		styles.setTo( 'margin:1px 1px 90.1rem;' );
 
 		expect( styles.getInlineStyle() ).to.equal( 'margin:1px 1px 90.1rem;' );
 		expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px 1px 90.1rem' );
@@ -104,7 +104,7 @@ describe( 'Margin styles normalizer', () => {
 	} );
 
 	it( 'should output inline style (4 values defined)', () => {
-		styles.setStyle( 'margin:1px .34cm 90.1rem thick;' );
+		styles.setTo( 'margin:1px .34cm 90.1rem thick;' );
 
 		expect( styles.getInlineStyle() ).to.equal( 'margin:1px .34cm 90.1rem thick;' );
 		expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px .34cm 90.1rem thick' );
@@ -115,7 +115,7 @@ describe( 'Margin styles normalizer', () => {
 	} );
 
 	it( 'should output inline style (4 values defined, only last different)', () => {
-		styles.setStyle( 'margin:1px 1px 1px thick;' );
+		styles.setTo( 'margin:1px 1px 1px thick;' );
 
 		expect( styles.getInlineStyle() ).to.equal( 'margin:1px 1px 1px thick;' );
 		expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px 1px 1px thick' );
@@ -127,14 +127,14 @@ describe( 'Margin styles normalizer', () => {
 
 	describe( 'margin-*', () => {
 		it( 'should set proper margin', () => {
-			styles.setStyle( 'margin-top:1px;' );
+			styles.setTo( 'margin-top:1px;' );
 
 			expect( styles.getNormalized( 'margin' ) ).to.deep.equal( { top: '1px' } );
 			expect( styles.getNormalized( 'margin-top' ) ).to.equal( '1px' );
 		} );
 
 		it( 'should merge margin with margin shorthand', () => {
-			styles.setStyle( 'margin: 2em;margin-top:1px;' );
+			styles.setTo( 'margin: 2em;margin-top:1px;' );
 
 			expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
 				top: '1px',
@@ -149,28 +149,28 @@ describe( 'Margin styles normalizer', () => {
 		} );
 
 		it( 'should output margin-top', () => {
-			styles.setStyle( 'margin-top:1px;' );
+			styles.setTo( 'margin-top:1px;' );
 
 			expect( styles.getInlineStyle() ).to.equal( 'margin-top:1px;' );
 			expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
 		} );
 
 		it( 'should output margin-right', () => {
-			styles.setStyle( 'margin-right:1px;' );
+			styles.setTo( 'margin-right:1px;' );
 
 			expect( styles.getInlineStyle() ).to.equal( 'margin-right:1px;' );
 			expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '1px' );
 		} );
 
 		it( 'should output margin-bottom', () => {
-			styles.setStyle( 'margin-bottom:1px;' );
+			styles.setTo( 'margin-bottom:1px;' );
 
 			expect( styles.getInlineStyle() ).to.equal( 'margin-bottom:1px;' );
 			expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '1px' );
 		} );
 
 		it( 'should output margin-left', () => {
-			styles.setStyle( 'margin-left:1px;' );
+			styles.setTo( 'margin-left:1px;' );
 
 			expect( styles.getInlineStyle() ).to.equal( 'margin-left:1px;' );
 			expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( '1px' );

+ 6 - 6
packages/ckeditor5-engine/tests/view/styles/paddingstyles.js

@@ -16,7 +16,7 @@ describe( 'Padding styles normalization', () => {
 	} );
 
 	it( 'should set all paddings (1 value defined)', () => {
-		styles.setStyle( 'padding:1px;' );
+		styles.setTo( 'padding:1px;' );
 
 		expect( styles.getNormalized( 'padding' ) ).to.deep.equal( {
 			top: '1px',
@@ -27,7 +27,7 @@ describe( 'Padding styles normalization', () => {
 	} );
 
 	it( 'should set all paddings (2 values defined)', () => {
-		styles.setStyle( 'padding:1px .34cm;' );
+		styles.setTo( 'padding:1px .34cm;' );
 
 		expect( styles.getNormalized( 'padding' ) ).to.deep.equal( {
 			top: '1px',
@@ -38,7 +38,7 @@ describe( 'Padding styles normalization', () => {
 	} );
 
 	it( 'should set all paddings (3 values defined)', () => {
-		styles.setStyle( 'padding:1px .34cm 90.1rem;' );
+		styles.setTo( 'padding:1px .34cm 90.1rem;' );
 
 		expect( styles.getNormalized( 'padding' ) ).to.deep.equal( {
 			top: '1px',
@@ -49,7 +49,7 @@ describe( 'Padding styles normalization', () => {
 	} );
 
 	it( 'should set all paddings (4 values defined)', () => {
-		styles.setStyle( 'padding:1px .34cm 90.1rem thick;' );
+		styles.setTo( 'padding:1px .34cm 90.1rem thick;' );
 
 		expect( styles.getNormalized( 'padding' ) ).to.deep.equal( {
 			top: '1px',
@@ -61,7 +61,7 @@ describe( 'Padding styles normalization', () => {
 
 	describe( 'padding-*', () => {
 		it( 'should set proper padding', () => {
-			styles.setStyle( 'padding-top:1px;' );
+			styles.setTo( 'padding-top:1px;' );
 
 			expect( styles.getNormalized( 'padding' ) ).to.deep.equal( {
 				top: '1px'
@@ -69,7 +69,7 @@ describe( 'Padding styles normalization', () => {
 		} );
 
 		it( 'should set proper padding with padding shorthand', () => {
-			styles.setStyle( 'padding: 2em;padding-top:1px;' );
+			styles.setTo( 'padding: 2em;padding-top:1px;' );
 
 			expect( styles.getNormalized( 'padding' ) ).to.deep.equal( {
 				top: '1px',

+ 28 - 28
packages/ckeditor5-engine/tests/view/stylesmap.js

@@ -33,71 +33,71 @@ describe( 'StylesMap', () => {
 		} );
 
 		it( 'should return number of set styles', () => {
-			styles.setStyle( 'color:blue' );
+			styles.setTo( 'color:blue' );
 			expect( styles.size ).to.equal( 1 );
 
-			styles.setStyle( 'margin:1px;' );
+			styles.setTo( 'margin:1px;' );
 			expect( styles.size ).to.equal( 1 );
 
-			styles.setStyle( 'margin-top:1px;margin-bottom:1px;' );
+			styles.setTo( 'margin-top:1px;margin-bottom:1px;' );
 			expect( styles.size ).to.equal( 2 );
 		} );
 	} );
 
-	describe( 'setStyle()', () => {
+	describe( 'setTo()', () => {
 		it( 'should reset styles to a new value', () => {
-			styles.setStyle( 'color:red;margin:1px;' );
+			styles.setTo( 'color:red;margin:1px;' );
 
 			expect( styles.getNormalized() ).to.deep.equal( { color: 'red', margin: '1px' } );
 
-			styles.setStyle( 'overflow:hidden;' );
+			styles.setTo( 'overflow:hidden;' );
 
 			expect( styles.getNormalized() ).to.deep.equal( { overflow: 'hidden' } );
 		} );
 
 		describe( 'styles parsing edge cases and incorrect styles', () => {
 			it( 'should not crash and not add any styles if styles attribute was empty', () => {
-				styles.setStyle( '' );
+				styles.setTo( '' );
 
 				expect( styles.getStyleNames() ).to.deep.equal( [] );
 			} );
 
 			it( 'should be able to parse big styles definition', () => {
 				expect( () => {
-					styles.setStyle( `background-image:url('data:image/jpeg;base64,${ encodedImage }')` );
+					styles.setTo( `background-image:url('data:image/jpeg;base64,${ encodedImage }')` );
 				} ).not.to.throw();
 			} );
 
 			it( 'should work with both types of quotes and ignore values inside quotes', () => {
-				styles.setStyle( 'background-image:url("im;color:g.jpg")' );
+				styles.setTo( 'background-image:url("im;color:g.jpg")' );
 				expect( styles.getInlineProperty( 'background-image' ) ).to.equal( 'url("im;color:g.jpg")' );
 
-				styles.setStyle( 'background-image:url(\'im;color:g.jpg\')' );
+				styles.setTo( 'background-image:url(\'im;color:g.jpg\')' );
 				expect( styles.getInlineProperty( 'background-image' ) ).to.equal( 'url(\'im;color:g.jpg\')' );
 			} );
 
 			it( 'should not be confused by whitespaces', () => {
-				styles.setStyle( '\ncolor:\n red ' );
+				styles.setTo( '\ncolor:\n red ' );
 
 				expect( styles.getInlineProperty( 'color' ) ).to.equal( 'red' );
 			} );
 
 			it( 'should not be confused by duplicated semicolon', () => {
-				styles.setStyle( 'color: red;; display: inline' );
+				styles.setTo( 'color: red;; display: inline' );
 
 				expect( styles.getInlineProperty( 'color' ) ).to.equal( 'red' );
 				expect( styles.getInlineProperty( 'display' ) ).to.equal( 'inline' );
 			} );
 
 			it( 'should not throw when value is missing', () => {
-				styles.setStyle( 'color:; display: inline' );
+				styles.setTo( 'color:; display: inline' );
 
 				expect( styles.getInlineProperty( 'color' ) ).to.equal( '' );
 				expect( styles.getInlineProperty( 'display' ) ).to.equal( 'inline' );
 			} );
 
 			it( 'should not throw when colon is duplicated', () => {
-				styles.setStyle( 'color:: red; display: inline' );
+				styles.setTo( 'color:: red; display: inline' );
 
 				// The result makes no sense, but here we just check that the algorithm doesn't crash.
 				expect( styles.getInlineProperty( 'color' ) ).to.equal( ': red' );
@@ -105,7 +105,7 @@ describe( 'StylesMap', () => {
 			} );
 
 			it( 'should not throw when random stuff passed', () => {
-				styles.setStyle( 'color: red;:; ;;" ":  display: inline; \'aaa;:' );
+				styles.setTo( 'color: red;:; ;;" ":  display: inline; \'aaa;:' );
 
 				// The result makes no sense, but here we just check that the algorithm doesn't crash.
 				expect( styles.getInlineProperty( 'color' ) ).to.equal( 'red' );
@@ -120,7 +120,7 @@ describe( 'StylesMap', () => {
 		} );
 
 		it( 'should return sorted styles string if styles are set', () => {
-			styles.setStyle( 'margin-top:1px;color:blue;' );
+			styles.setTo( 'margin-top:1px;color:blue;' );
 
 			expect( styles.getInlineStyle() ).to.equal( 'color:blue;margin-top:1px;' );
 		} );
@@ -128,7 +128,7 @@ describe( 'StylesMap', () => {
 
 	describe( 'getInlineProperty', () => {
 		it( 'should return empty string for missing shorthand', () => {
-			styles.setStyle( 'margin-top:1px' );
+			styles.setTo( 'margin-top:1px' );
 
 			expect( styles.getInlineProperty( 'margin' ) ).to.be.undefined;
 		} );
@@ -144,19 +144,19 @@ describe( 'StylesMap', () => {
 		} );
 
 		it( 'should return false if normalized property is not set', () => {
-			styles.setStyle( 'foo-top:1px' );
+			styles.setTo( 'foo-top:1px' );
 
 			expect( styles.hasProperty( 'foo' ) ).to.be.true;
 		} );
 
 		it( 'should return true if property is set', () => {
-			styles.setStyle( 'bar:deeppink' );
+			styles.setTo( 'bar:deeppink' );
 
 			expect( styles.hasProperty( 'bar' ) ).to.be.true;
 		} );
 
 		it( 'should return true if normalized shorthanded property is set', () => {
-			styles.setStyle( 'foo:1px' );
+			styles.setTo( 'foo:1px' );
 
 			expect( styles.hasProperty( 'foo' ) ).to.be.true;
 			expect( styles.hasProperty( 'foo-top' ) ).to.be.true;
@@ -171,21 +171,21 @@ describe( 'StylesMap', () => {
 		} );
 
 		it( 'should insert new property (other properties are set)', () => {
-			styles.setStyle( 'margin: 1px;' );
+			styles.setTo( 'margin: 1px;' );
 			styles.insertProperty( 'color', 'blue' );
 
 			expect( styles.getInlineProperty( 'color' ) ).to.equal( 'blue' );
 		} );
 
 		it( 'should overwrite property', () => {
-			styles.setStyle( 'color: red;' );
+			styles.setTo( 'color: red;' );
 			styles.insertProperty( 'color', 'blue' );
 
 			expect( styles.getInlineProperty( 'color' ) ).to.equal( 'blue' );
 		} );
 
 		it( 'should set multiple styles by providing an object', () => {
-			styles.setStyle( 'color: red;' );
+			styles.setTo( 'color: red;' );
 			styles.insertProperty( { color: 'blue', foo: '1px' } );
 
 			expect( styles.getInlineProperty( 'color' ) ).to.equal( 'blue' );
@@ -193,7 +193,7 @@ describe( 'StylesMap', () => {
 		} );
 
 		it( 'should set object property', () => {
-			styles.setStyle( 'foo:1px;' );
+			styles.setTo( 'foo:1px;' );
 			styles.insertProperty( 'foo', { right: '2px' } );
 
 			expect( styles.getInlineProperty( 'foo-left' ) ).to.equal( '1px' );
@@ -209,14 +209,14 @@ describe( 'StylesMap', () => {
 		} );
 
 		it( 'should insert new property (other properties are set)', () => {
-			styles.setStyle( 'color:blue' );
+			styles.setTo( 'color:blue' );
 			styles.removeProperty( 'color' );
 
 			expect( styles.getInlineProperty( 'color' ) ).to.be.undefined;
 		} );
 
 		it( 'should remove normalized property', () => {
-			styles.setStyle( 'margin:1px' );
+			styles.setTo( 'margin:1px' );
 
 			styles.removeProperty( 'margin-top' );
 
@@ -230,13 +230,13 @@ describe( 'StylesMap', () => {
 		} );
 
 		it( 'should output custom style names', () => {
-			styles.setStyle( 'foo: 2;bar: baz;foo-bar-baz:none;' );
+			styles.setTo( 'foo: 2;bar: baz;foo-bar-baz:none;' );
 
 			expect( styles.getStyleNames() ).to.deep.equal( [ 'foo', 'bar', 'foo-bar-baz' ] );
 		} );
 
 		it( 'should output full names for known style names', () => {
-			styles.setStyle( 'foo: 1px;foo-top: 2em;' );
+			styles.setTo( 'foo: 1px;foo-top: 2em;' );
 
 			expect( styles.getStyleNames() ).to.deep.equal( [ 'foo' ] );
 		} );