@elementor/editor-canvas 0.20.0 → 0.21.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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +14 -0
- package/dist/index.js +61 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/styles-prop-resolver.test.ts +111 -11
- package/src/init-style-transformers.ts +2 -1
- package/src/transformers/styles/background-image-overlay-transformer.ts +13 -6
- package/src/transformers/styles/background-overlay-transformer.ts +77 -0
- package/src/transformers/styles/background-transformer.ts +8 -4
|
@@ -168,7 +168,7 @@ describe( 'styles prop resolver', () => {
|
|
|
168
168
|
} ),
|
|
169
169
|
},
|
|
170
170
|
expected: {
|
|
171
|
-
background: '#ee00ff',
|
|
171
|
+
'background-color': '#ee00ff',
|
|
172
172
|
},
|
|
173
173
|
},
|
|
174
174
|
{
|
|
@@ -189,7 +189,7 @@ describe( 'styles prop resolver', () => {
|
|
|
189
189
|
} ),
|
|
190
190
|
},
|
|
191
191
|
expected: {
|
|
192
|
-
background: 'url(https://localhost.test/test-image.png)',
|
|
192
|
+
'background-image': 'url(https://localhost.test/test-image.png)',
|
|
193
193
|
},
|
|
194
194
|
},
|
|
195
195
|
{
|
|
@@ -250,11 +250,13 @@ describe( 'styles prop resolver', () => {
|
|
|
250
250
|
} ),
|
|
251
251
|
},
|
|
252
252
|
expected: {
|
|
253
|
-
background:
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
'url(medium_large-image-url-123)
|
|
257
|
-
|
|
253
|
+
'background-color': '#000',
|
|
254
|
+
'background-attachment': 'scroll,scroll,scroll,fixed',
|
|
255
|
+
'background-image':
|
|
256
|
+
'linear-gradient(blue, blue),linear-gradient(yellow, yellow),url(thumbnail-image-url-123),url(medium_large-image-url-123)',
|
|
257
|
+
'background-position': '0% 0%,0% 0%,0% 0%,200px 30px',
|
|
258
|
+
'background-repeat': 'repeat,repeat,repeat,repeat-x',
|
|
259
|
+
'background-size': 'auto auto,auto auto,1400px auto,auto',
|
|
258
260
|
},
|
|
259
261
|
},
|
|
260
262
|
{
|
|
@@ -291,7 +293,75 @@ describe( 'styles prop resolver', () => {
|
|
|
291
293
|
} ),
|
|
292
294
|
},
|
|
293
295
|
expected: {
|
|
294
|
-
background: 'url(medium_large-image-url-123)
|
|
296
|
+
'background-image': 'url(medium_large-image-url-123),url(thumbnail-image-url-123)',
|
|
297
|
+
'background-attachment': 'scroll,fixed',
|
|
298
|
+
'background-repeat': 'repeat-x,repeat',
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
name: 'background (same url and position, attachment with only defaults, different repeat)',
|
|
303
|
+
prepare: () => {
|
|
304
|
+
jest.mocked( getMediaAttachment ).mockImplementation(
|
|
305
|
+
( args ) => Promise.resolve( mockAttachmentData( args.id ) ) as never
|
|
306
|
+
);
|
|
307
|
+
},
|
|
308
|
+
props: {
|
|
309
|
+
background: backgroundPropTypeUtil.create( {
|
|
310
|
+
'background-overlay': backgroundOverlayPropTypeUtil.create( [
|
|
311
|
+
backgroundImageOverlayPropTypeUtil.create( {
|
|
312
|
+
image: imagePropTypeUtil.create( {
|
|
313
|
+
src: imageSrcPropTypeUtil.create( {
|
|
314
|
+
id: imageAttachmentIdPropType.create( 123 ),
|
|
315
|
+
url: null,
|
|
316
|
+
} ),
|
|
317
|
+
size: 'medium_large',
|
|
318
|
+
} ),
|
|
319
|
+
position: 'center left',
|
|
320
|
+
repeat: 'repeat-x',
|
|
321
|
+
attachment: 'scroll',
|
|
322
|
+
} ),
|
|
323
|
+
backgroundImageOverlayPropTypeUtil.create( {
|
|
324
|
+
image: imagePropTypeUtil.create( {
|
|
325
|
+
src: imageSrcPropTypeUtil.create( {
|
|
326
|
+
id: imageAttachmentIdPropType.create( 123 ),
|
|
327
|
+
url: null,
|
|
328
|
+
} ),
|
|
329
|
+
size: 'medium_large',
|
|
330
|
+
} ),
|
|
331
|
+
position: 'center left',
|
|
332
|
+
repeat: 'no-repeat',
|
|
333
|
+
} ),
|
|
334
|
+
backgroundImageOverlayPropTypeUtil.create( {
|
|
335
|
+
image: imagePropTypeUtil.create( {
|
|
336
|
+
src: imageSrcPropTypeUtil.create( {
|
|
337
|
+
id: imageAttachmentIdPropType.create( 123 ),
|
|
338
|
+
url: null,
|
|
339
|
+
} ),
|
|
340
|
+
size: 'medium_large',
|
|
341
|
+
} ),
|
|
342
|
+
position: 'center left',
|
|
343
|
+
repeat: 'repeat',
|
|
344
|
+
attachment: 'scroll',
|
|
345
|
+
} ),
|
|
346
|
+
backgroundImageOverlayPropTypeUtil.create( {
|
|
347
|
+
image: imagePropTypeUtil.create( {
|
|
348
|
+
src: imageSrcPropTypeUtil.create( {
|
|
349
|
+
id: imageAttachmentIdPropType.create( 123 ),
|
|
350
|
+
url: null,
|
|
351
|
+
} ),
|
|
352
|
+
size: 'medium_large',
|
|
353
|
+
} ),
|
|
354
|
+
position: 'center left',
|
|
355
|
+
} ),
|
|
356
|
+
] ),
|
|
357
|
+
} ),
|
|
358
|
+
},
|
|
359
|
+
expected: {
|
|
360
|
+
'background-image':
|
|
361
|
+
'url(medium_large-image-url-123),url(medium_large-image-url-123),url(medium_large-image-url-123),url(medium_large-image-url-123)',
|
|
362
|
+
'background-position': 'center left',
|
|
363
|
+
'background-repeat': 'repeat-x,no-repeat,repeat,repeat',
|
|
364
|
+
'background-attachment': 'scroll',
|
|
295
365
|
},
|
|
296
366
|
},
|
|
297
367
|
{
|
|
@@ -336,9 +406,39 @@ describe( 'styles prop resolver', () => {
|
|
|
336
406
|
} ),
|
|
337
407
|
},
|
|
338
408
|
expected: {
|
|
339
|
-
background:
|
|
340
|
-
'linear-gradient(190deg, red 10%,yellow 40%,rgb(255,0,255) 87%),'
|
|
341
|
-
|
|
409
|
+
'background-image':
|
|
410
|
+
'linear-gradient(190deg, red 10%,yellow 40%,rgb(255,0,255) 87%),radial-gradient(circle at bottom left, rgb(0,190,245,0.7) 60%,rgb(255,0,255) 93%)',
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
name: 'background with manually set default values',
|
|
415
|
+
props: {
|
|
416
|
+
background: backgroundPropTypeUtil.create( {
|
|
417
|
+
color: colorPropTypeUtil.create( '#000' ),
|
|
418
|
+
'background-overlay': backgroundOverlayPropTypeUtil.create( [
|
|
419
|
+
backgroundImageOverlayPropTypeUtil.create( {
|
|
420
|
+
image: imagePropTypeUtil.create( {
|
|
421
|
+
src: imageSrcPropTypeUtil.create( {
|
|
422
|
+
id: imageAttachmentIdPropType.create( 123 ),
|
|
423
|
+
url: null,
|
|
424
|
+
} ),
|
|
425
|
+
} ),
|
|
426
|
+
repeat: stringPropTypeUtil.create( 'repeat' ),
|
|
427
|
+
size: backgroundImageSizeScalePropTypeUtil.create( {
|
|
428
|
+
width: sizePropTypeUtil.create( {
|
|
429
|
+
size: 1400,
|
|
430
|
+
unit: 'px',
|
|
431
|
+
} ),
|
|
432
|
+
} ),
|
|
433
|
+
} ),
|
|
434
|
+
] ),
|
|
435
|
+
} ),
|
|
436
|
+
},
|
|
437
|
+
expected: {
|
|
438
|
+
'background-color': '#000',
|
|
439
|
+
'background-image': 'url(original-image-url-123)',
|
|
440
|
+
'background-repeat': 'repeat',
|
|
441
|
+
'background-size': '1400px auto',
|
|
342
442
|
},
|
|
343
443
|
},
|
|
344
444
|
] )( 'it should resolve props for `$name`', async ( { prepare, props, expected } ) => {
|
|
@@ -7,6 +7,7 @@ import { backgroundGradientOverlayTransformer } from './transformers/styles/back
|
|
|
7
7
|
import { backgroundImageOverlayTransformer } from './transformers/styles/background-image-overlay-transformer';
|
|
8
8
|
import { backgroundImagePositionOffsetTransformer } from './transformers/styles/background-image-position-offset-transformer';
|
|
9
9
|
import { backgroundImageSizeScaleTransformer } from './transformers/styles/background-image-size-scale-transformer';
|
|
10
|
+
import { backgroundOverlayTransformer } from './transformers/styles/background-overlay-transformer';
|
|
10
11
|
import { backgroundTransformer } from './transformers/styles/background-transformer';
|
|
11
12
|
import { colorStopTransformer } from './transformers/styles/color-stop-transformer';
|
|
12
13
|
import { createCombineArrayTransformer } from './transformers/styles/create-combine-array-transformer';
|
|
@@ -29,7 +30,7 @@ export function initStyleTransformers() {
|
|
|
29
30
|
)
|
|
30
31
|
.register( 'box-shadow', createCombineArrayTransformer( ',' ) )
|
|
31
32
|
.register( 'background', backgroundTransformer )
|
|
32
|
-
.register( 'background-overlay',
|
|
33
|
+
.register( 'background-overlay', backgroundOverlayTransformer )
|
|
33
34
|
.register( 'background-color-overlay', backgroundColorOverlayTransformer )
|
|
34
35
|
.register( 'background-image-overlay', backgroundImageOverlayTransformer )
|
|
35
36
|
.register( 'background-gradient-overlay', backgroundGradientOverlayTransformer )
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { createTransformer } from '../create-transformer';
|
|
2
2
|
|
|
3
|
-
const DEFAULT_POSITION_VALUE = '0% 0%';
|
|
4
|
-
|
|
5
3
|
type BackgroundImageOverlay = {
|
|
6
4
|
image?: {
|
|
7
5
|
src?: string;
|
|
@@ -12,6 +10,14 @@ type BackgroundImageOverlay = {
|
|
|
12
10
|
attachment?: string;
|
|
13
11
|
};
|
|
14
12
|
|
|
13
|
+
export type BackgroundImageTransformed = {
|
|
14
|
+
src: string | null;
|
|
15
|
+
repeat: string | null;
|
|
16
|
+
attachment: string | null;
|
|
17
|
+
size: string | null;
|
|
18
|
+
position: string | null;
|
|
19
|
+
};
|
|
20
|
+
|
|
15
21
|
export const backgroundImageOverlayTransformer = createTransformer( ( value: BackgroundImageOverlay ) => {
|
|
16
22
|
const { image, size = null, position = null, repeat = null, attachment = null } = value;
|
|
17
23
|
|
|
@@ -21,12 +27,13 @@ export const backgroundImageOverlayTransformer = createTransformer( ( value: Bac
|
|
|
21
27
|
|
|
22
28
|
const src = image.src ? `url(${ image.src })` : null;
|
|
23
29
|
|
|
24
|
-
const backgroundStyles =
|
|
30
|
+
const backgroundStyles: BackgroundImageTransformed = {
|
|
25
31
|
src,
|
|
26
32
|
repeat,
|
|
27
33
|
attachment,
|
|
28
|
-
size
|
|
29
|
-
|
|
34
|
+
size,
|
|
35
|
+
position,
|
|
36
|
+
};
|
|
30
37
|
|
|
31
|
-
return backgroundStyles
|
|
38
|
+
return backgroundStyles;
|
|
32
39
|
} );
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { createTransformer } from '../create-transformer';
|
|
2
|
+
import { type BackgroundImageTransformed } from './background-image-overlay-transformer';
|
|
3
|
+
|
|
4
|
+
type BackgroundOverlay = ( BackgroundImageTransformed | string )[];
|
|
5
|
+
|
|
6
|
+
export type BackgroundOverlayTransformed = {
|
|
7
|
+
'background-image'?: string | null;
|
|
8
|
+
'background-repeat'?: string | null;
|
|
9
|
+
'background-attachment'?: string | null;
|
|
10
|
+
'background-size'?: string | null;
|
|
11
|
+
'background-position'?: string | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const backgroundOverlayTransformer = createTransformer(
|
|
15
|
+
( value: BackgroundOverlay ): BackgroundOverlayTransformed | null => {
|
|
16
|
+
if ( ! value || value.length === 0 ) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const normalizedValues = normalizeOverlayValues( value );
|
|
21
|
+
|
|
22
|
+
const images = getValuesString( normalizedValues, 'src', 'none', true );
|
|
23
|
+
const repeats = getValuesString( normalizedValues, 'repeat', 'repeat' );
|
|
24
|
+
const attachments = getValuesString( normalizedValues, 'attachment', 'scroll' );
|
|
25
|
+
const sizes = getValuesString( normalizedValues, 'size', 'auto auto' );
|
|
26
|
+
const positions = getValuesString( normalizedValues, 'position', '0% 0%' );
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
'background-image': images,
|
|
30
|
+
'background-repeat': repeats,
|
|
31
|
+
'background-attachment': attachments,
|
|
32
|
+
'background-size': sizes,
|
|
33
|
+
'background-position': positions,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
function normalizeOverlayValues( overlays: BackgroundOverlay ): BackgroundImageTransformed[] {
|
|
39
|
+
return overlays.map( ( item ) => {
|
|
40
|
+
if ( typeof item === 'string' ) {
|
|
41
|
+
return {
|
|
42
|
+
src: item,
|
|
43
|
+
repeat: null,
|
|
44
|
+
attachment: null,
|
|
45
|
+
size: null,
|
|
46
|
+
position: null,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return item;
|
|
51
|
+
} );
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getValuesString(
|
|
55
|
+
items: Partial< BackgroundImageTransformed >[],
|
|
56
|
+
prop: keyof BackgroundImageTransformed,
|
|
57
|
+
defaultValue: string,
|
|
58
|
+
preventUnification: boolean = false
|
|
59
|
+
) {
|
|
60
|
+
const isEmpty = items.filter( ( item ) => item?.[ prop ] ).length === 0;
|
|
61
|
+
|
|
62
|
+
if ( isEmpty ) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const formattedValues = items.map( ( item ) => item[ prop ] ?? defaultValue );
|
|
67
|
+
|
|
68
|
+
if ( ! preventUnification ) {
|
|
69
|
+
const allSame = formattedValues.every( ( value ) => value === formattedValues[ 0 ] );
|
|
70
|
+
|
|
71
|
+
if ( allSame ) {
|
|
72
|
+
return formattedValues[ 0 ];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return formattedValues.join( ',' );
|
|
77
|
+
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
import { createMultiPropsValue } from '../../renderers/multi-props';
|
|
1
2
|
import { createTransformer } from '../create-transformer';
|
|
3
|
+
import { type BackgroundOverlayTransformed } from './background-overlay-transformer';
|
|
2
4
|
|
|
3
5
|
type Background = {
|
|
4
|
-
'background-overlay'?:
|
|
6
|
+
'background-overlay'?: BackgroundOverlayTransformed;
|
|
5
7
|
color?: string;
|
|
6
8
|
};
|
|
7
9
|
|
|
8
10
|
export const backgroundTransformer = createTransformer( ( value: Background ) => {
|
|
9
|
-
const
|
|
10
|
-
const color = value.color ?? '';
|
|
11
|
+
const { color = null, 'background-overlay': overlays = null } = value;
|
|
11
12
|
|
|
12
|
-
return
|
|
13
|
+
return createMultiPropsValue( {
|
|
14
|
+
...overlays,
|
|
15
|
+
'background-color': color,
|
|
16
|
+
} );
|
|
13
17
|
} );
|