@elementor/editor-canvas 0.7.1 → 0.9.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 +9 -9
- package/CHANGELOG.md +57 -0
- package/dist/index.js +241 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +243 -217
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -12
- package/src/__tests__/init-styles-renderer.test.ts +19 -9
- package/src/init-styles-renderer.ts +20 -7
- package/src/{styles-renderer → renderers}/__tests__/__mocks__/styles-schema.ts +214 -16
- package/src/renderers/__tests__/create-props-resolver.test.ts +175 -0
- package/src/renderers/__tests__/create-props-resolver.transformers.test.ts +325 -0
- package/src/renderers/__tests__/render-styles.test.ts +126 -0
- package/src/renderers/create-props-resolver.ts +123 -0
- package/src/{styles-renderer → renderers}/multi-props.ts +1 -1
- package/src/{styles-renderer/render.ts → renderers/render-styles.ts} +18 -17
- package/src/renderers/style-transformers/background-image-overlay-transformer.ts +24 -0
- package/src/renderers/style-transformers/background-image-position-offset-transformer.ts +10 -0
- package/src/renderers/style-transformers/background-image-size-scale-transformer.ts +10 -0
- package/src/{styles-renderer/transformers → renderers/style-transformers}/create-corner-sizes-transformer.ts +7 -9
- package/src/{styles-renderer/transformers → renderers/style-transformers}/create-edge-sizes-transformer.ts +2 -2
- package/src/{styles-renderer/transformers → renderers/style-transformers}/image-attachment.ts +1 -1
- package/src/{styles-renderer/transformers → renderers/style-transformers}/image-src.ts +4 -7
- package/src/renderers/style-transformers/image.ts +25 -0
- package/src/{styles-renderer/transformers → renderers/style-transformers}/index.ts +9 -2
- package/src/renderers/style-transformers/stroke-transformer.ts +16 -0
- package/src/renderers/types.ts +12 -0
- package/src/styles-renderer/__tests__/enqueue-used-fonts.test.ts +0 -60
- package/src/styles-renderer/__tests__/index.test.ts +0 -777
- package/src/styles-renderer/enqueue-used-fonts.ts +0 -22
- package/src/styles-renderer/index.ts +0 -2
- package/src/styles-renderer/resolve.ts +0 -103
- package/src/styles-renderer/transformers/background-image-overlay-transformer.ts +0 -31
- package/src/styles-renderer/transformers/stroke-transformer.ts +0 -9
- package/src/styles-renderer/types.ts +0 -16
- /package/src/{styles-renderer → renderers}/errors.ts +0 -0
- /package/src/{styles-renderer/transformers → renderers/style-transformers}/background-color-overlay-transformer.ts +0 -0
- /package/src/{styles-renderer/transformers → renderers/style-transformers}/background-transformer.ts +0 -0
- /package/src/{styles-renderer/transformers → renderers/style-transformers}/create-combine-array-transformer.ts +0 -0
- /package/src/{styles-renderer/transformers → renderers/style-transformers}/dimensions.ts +0 -0
- /package/src/{styles-renderer/transformers → renderers/style-transformers}/layout-direction-transformer.ts +0 -0
- /package/src/{styles-renderer/transformers → renderers/style-transformers}/primitive-transformer.ts +0 -0
- /package/src/{styles-renderer/transformers → renderers/style-transformers}/shadow-transformer.ts +0 -0
- /package/src/{styles-renderer/transformers → renderers/style-transformers}/size-transformer.ts +0 -0
|
@@ -1,777 +0,0 @@
|
|
|
1
|
-
/* eslint-disable testing-library/render-result-naming-convention */
|
|
2
|
-
import { createMockStyleDefinition } from 'test-utils';
|
|
3
|
-
import {
|
|
4
|
-
backgroundColorOverlayPropTypeUtil,
|
|
5
|
-
backgroundImageOverlayPropTypeUtil,
|
|
6
|
-
backgroundOverlayPropTypeUtil,
|
|
7
|
-
backgroundPropTypeUtil,
|
|
8
|
-
borderRadiusPropTypeUtil,
|
|
9
|
-
borderWidthPropTypeUtil,
|
|
10
|
-
boxShadowPropTypeUtil,
|
|
11
|
-
colorPropTypeUtil,
|
|
12
|
-
dimensionsPropTypeUtil,
|
|
13
|
-
imageAttachmentIdPropType,
|
|
14
|
-
imageSrcPropTypeUtil,
|
|
15
|
-
layoutDirectionPropTypeUtil,
|
|
16
|
-
shadowPropTypeUtil,
|
|
17
|
-
sizePropTypeUtil,
|
|
18
|
-
strokePropTypeUtil,
|
|
19
|
-
} from '@elementor/editor-props';
|
|
20
|
-
import type { BreakpointsMap } from '@elementor/editor-responsive';
|
|
21
|
-
import { getStylesSchema, type StyleDefinition } from '@elementor/editor-styles';
|
|
22
|
-
import { getMediaAttachment } from '@elementor/wp-media';
|
|
23
|
-
|
|
24
|
-
import render from '../render';
|
|
25
|
-
import transformers from '../transformers';
|
|
26
|
-
import backgroundTransformer from '../transformers/background-transformer';
|
|
27
|
-
import { stylesSchemaMock } from './__mocks__/styles-schema';
|
|
28
|
-
|
|
29
|
-
jest.mock( '@elementor/editor-styles' );
|
|
30
|
-
jest.mock( '@elementor/wp-media' );
|
|
31
|
-
|
|
32
|
-
describe( 'styles-renderer', () => {
|
|
33
|
-
beforeEach( () => {
|
|
34
|
-
jest.mocked( getStylesSchema ).mockReturnValue( stylesSchemaMock );
|
|
35
|
-
} );
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Prop Types
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
it( 'should transform stroke (including also size, number, string & color)', async () => {
|
|
42
|
-
const styleDef = createMockStyleDefinition( {
|
|
43
|
-
id: 'test',
|
|
44
|
-
props: {
|
|
45
|
-
'text-stroke': strokePropTypeUtil.create( {
|
|
46
|
-
width: sizePropTypeUtil.create( {
|
|
47
|
-
size: 1,
|
|
48
|
-
unit: 'px',
|
|
49
|
-
} ),
|
|
50
|
-
color: colorPropTypeUtil.create( '#000000' ),
|
|
51
|
-
} ),
|
|
52
|
-
},
|
|
53
|
-
} );
|
|
54
|
-
|
|
55
|
-
const cssString = await render( {
|
|
56
|
-
styles: [ styleDef ],
|
|
57
|
-
transformers,
|
|
58
|
-
breakpoints: mockBreakpoints,
|
|
59
|
-
} );
|
|
60
|
-
|
|
61
|
-
expect( cssString ).toBe( `<style data-style-id="test">.test{text-stroke:1px #000000;}</style>` );
|
|
62
|
-
} );
|
|
63
|
-
|
|
64
|
-
it( 'should transform box-shadow (including also shadow)', async () => {
|
|
65
|
-
// Arrange.
|
|
66
|
-
const shadow = shadowPropTypeUtil.create( {
|
|
67
|
-
hOffset: sizePropTypeUtil.create( {
|
|
68
|
-
size: 1,
|
|
69
|
-
unit: 'px',
|
|
70
|
-
} ),
|
|
71
|
-
vOffset: sizePropTypeUtil.create( {
|
|
72
|
-
size: 1,
|
|
73
|
-
unit: 'px',
|
|
74
|
-
} ),
|
|
75
|
-
blur: sizePropTypeUtil.create( {
|
|
76
|
-
size: 1,
|
|
77
|
-
unit: 'px',
|
|
78
|
-
} ),
|
|
79
|
-
spread: sizePropTypeUtil.create( {
|
|
80
|
-
size: 1,
|
|
81
|
-
unit: 'px',
|
|
82
|
-
} ),
|
|
83
|
-
color: colorPropTypeUtil.create( '#000000' ),
|
|
84
|
-
} );
|
|
85
|
-
|
|
86
|
-
const shadowInset = shadowPropTypeUtil.create(
|
|
87
|
-
( prev ) => ( {
|
|
88
|
-
...prev,
|
|
89
|
-
position: 'inset',
|
|
90
|
-
} ),
|
|
91
|
-
{ base: shadow }
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const styleDef = createMockStyleDefinition( {
|
|
95
|
-
id: 'test',
|
|
96
|
-
props: {
|
|
97
|
-
'box-shadow': boxShadowPropTypeUtil.create( [ shadow, shadowInset ] ),
|
|
98
|
-
},
|
|
99
|
-
} );
|
|
100
|
-
|
|
101
|
-
// Act.
|
|
102
|
-
const cssString = await render( {
|
|
103
|
-
styles: [ styleDef ],
|
|
104
|
-
transformers,
|
|
105
|
-
breakpoints: mockBreakpoints,
|
|
106
|
-
} );
|
|
107
|
-
|
|
108
|
-
// Assert.
|
|
109
|
-
expect( cssString ).toBe(
|
|
110
|
-
`<style data-style-id="test">.test{box-shadow:1px 1px 1px 1px #000000,1px 1px 1px 1px #000000 inset;}</style>`
|
|
111
|
-
);
|
|
112
|
-
} );
|
|
113
|
-
|
|
114
|
-
it( 'should transform linked-dimensions (including also size, number & string)', async () => {
|
|
115
|
-
// Arrange.
|
|
116
|
-
const styleDef = createMockStyleDefinition( {
|
|
117
|
-
id: 'test',
|
|
118
|
-
props: {
|
|
119
|
-
padding: dimensionsPropTypeUtil.create( {
|
|
120
|
-
top: sizePropTypeUtil.create( {
|
|
121
|
-
size: 10,
|
|
122
|
-
unit: 'px',
|
|
123
|
-
} ),
|
|
124
|
-
right: sizePropTypeUtil.create( {
|
|
125
|
-
size: 20,
|
|
126
|
-
unit: 'px',
|
|
127
|
-
} ),
|
|
128
|
-
bottom: sizePropTypeUtil.create( {
|
|
129
|
-
size: 30,
|
|
130
|
-
unit: 'px',
|
|
131
|
-
} ),
|
|
132
|
-
left: sizePropTypeUtil.create( {
|
|
133
|
-
size: 40,
|
|
134
|
-
unit: 'px',
|
|
135
|
-
} ),
|
|
136
|
-
} ),
|
|
137
|
-
},
|
|
138
|
-
} );
|
|
139
|
-
|
|
140
|
-
// Act.
|
|
141
|
-
const cssString = await render( {
|
|
142
|
-
styles: [ styleDef ],
|
|
143
|
-
transformers,
|
|
144
|
-
breakpoints: mockBreakpoints,
|
|
145
|
-
} );
|
|
146
|
-
|
|
147
|
-
// Assert.
|
|
148
|
-
expect( cssString ).toBe(
|
|
149
|
-
`<style data-style-id="test">.test{padding-top:10px;padding-right:20px;padding-bottom:30px;padding-left:40px;}</style>`
|
|
150
|
-
);
|
|
151
|
-
} );
|
|
152
|
-
|
|
153
|
-
it( 'should transform border-width (including also size, number & string)', async () => {
|
|
154
|
-
// Arrange.
|
|
155
|
-
const styleDef = createMockStyleDefinition( {
|
|
156
|
-
id: 'test',
|
|
157
|
-
props: {
|
|
158
|
-
'border-width': borderWidthPropTypeUtil.create( {
|
|
159
|
-
top: sizePropTypeUtil.create( {
|
|
160
|
-
size: 10,
|
|
161
|
-
unit: 'px',
|
|
162
|
-
} ),
|
|
163
|
-
right: sizePropTypeUtil.create( {
|
|
164
|
-
size: 20,
|
|
165
|
-
unit: 'px',
|
|
166
|
-
} ),
|
|
167
|
-
bottom: sizePropTypeUtil.create( {
|
|
168
|
-
size: 30,
|
|
169
|
-
unit: 'px',
|
|
170
|
-
} ),
|
|
171
|
-
left: sizePropTypeUtil.create( {
|
|
172
|
-
size: 40,
|
|
173
|
-
unit: 'px',
|
|
174
|
-
} ),
|
|
175
|
-
} ),
|
|
176
|
-
},
|
|
177
|
-
} );
|
|
178
|
-
// Act.
|
|
179
|
-
const cssString = await render( {
|
|
180
|
-
styles: [ styleDef ],
|
|
181
|
-
transformers,
|
|
182
|
-
breakpoints: mockBreakpoints,
|
|
183
|
-
} );
|
|
184
|
-
|
|
185
|
-
// Assert.
|
|
186
|
-
expect( cssString ).toBe(
|
|
187
|
-
`<style data-style-id="test">.test{border-top-width:10px;border-right-width:20px;border-bottom-width:30px;border-left-width:40px;}</style>`
|
|
188
|
-
);
|
|
189
|
-
} );
|
|
190
|
-
|
|
191
|
-
it( 'should transform border-radius (including also union, size, number & string)', async () => {
|
|
192
|
-
// Arrange.
|
|
193
|
-
const styleDef = createMockStyleDefinition( {
|
|
194
|
-
id: 'test',
|
|
195
|
-
props: {
|
|
196
|
-
'border-radius': borderRadiusPropTypeUtil.create( {
|
|
197
|
-
'top-left': sizePropTypeUtil.create( {
|
|
198
|
-
size: 10,
|
|
199
|
-
unit: 'px',
|
|
200
|
-
} ),
|
|
201
|
-
'top-right': sizePropTypeUtil.create( {
|
|
202
|
-
size: 20,
|
|
203
|
-
unit: 'px',
|
|
204
|
-
} ),
|
|
205
|
-
'bottom-right': sizePropTypeUtil.create( {
|
|
206
|
-
size: 30,
|
|
207
|
-
unit: 'px',
|
|
208
|
-
} ),
|
|
209
|
-
'bottom-left': sizePropTypeUtil.create( {
|
|
210
|
-
size: 40,
|
|
211
|
-
unit: 'px',
|
|
212
|
-
} ),
|
|
213
|
-
} ),
|
|
214
|
-
},
|
|
215
|
-
} );
|
|
216
|
-
|
|
217
|
-
// Act.
|
|
218
|
-
const cssString = await render( {
|
|
219
|
-
styles: [ styleDef ],
|
|
220
|
-
transformers,
|
|
221
|
-
breakpoints: mockBreakpoints,
|
|
222
|
-
} );
|
|
223
|
-
|
|
224
|
-
// Assert.
|
|
225
|
-
expect( cssString ).toBe(
|
|
226
|
-
`<style data-style-id="test">.test{border-top-left-radius:10px;border-top-right-radius:20px;border-bottom-right-radius:30px;border-bottom-left-radius:40px;}</style>`
|
|
227
|
-
);
|
|
228
|
-
} );
|
|
229
|
-
|
|
230
|
-
it( 'should transform layout direction', async () => {
|
|
231
|
-
// Arrange.
|
|
232
|
-
const styleDef = createMockStyleDefinition( {
|
|
233
|
-
id: 'test',
|
|
234
|
-
props: {
|
|
235
|
-
gap: layoutDirectionPropTypeUtil.create( {
|
|
236
|
-
row: sizePropTypeUtil.create( {
|
|
237
|
-
size: 10,
|
|
238
|
-
unit: 'px',
|
|
239
|
-
} ),
|
|
240
|
-
column: sizePropTypeUtil.create( {
|
|
241
|
-
size: 20,
|
|
242
|
-
unit: 'px',
|
|
243
|
-
} ),
|
|
244
|
-
} ),
|
|
245
|
-
},
|
|
246
|
-
} );
|
|
247
|
-
|
|
248
|
-
// Act.
|
|
249
|
-
const cssString = await render( {
|
|
250
|
-
styles: [ styleDef ],
|
|
251
|
-
transformers,
|
|
252
|
-
breakpoints: mockBreakpoints,
|
|
253
|
-
} );
|
|
254
|
-
|
|
255
|
-
// Assert.
|
|
256
|
-
expect( cssString ).toBe( `<style data-style-id="test">.test{column-gap:20px;row-gap:10px;}</style>` );
|
|
257
|
-
} );
|
|
258
|
-
/**
|
|
259
|
-
* Features
|
|
260
|
-
*/
|
|
261
|
-
|
|
262
|
-
it( 'should render media queries', async () => {
|
|
263
|
-
// Arrange.
|
|
264
|
-
const styleDef: StyleDefinition = {
|
|
265
|
-
id: 'test',
|
|
266
|
-
type: 'class',
|
|
267
|
-
label: 'Test',
|
|
268
|
-
variants: [
|
|
269
|
-
{
|
|
270
|
-
meta: {
|
|
271
|
-
breakpoint: null,
|
|
272
|
-
state: null,
|
|
273
|
-
},
|
|
274
|
-
props: {
|
|
275
|
-
'font-size': sizePropTypeUtil.create( {
|
|
276
|
-
size: 24,
|
|
277
|
-
unit: 'px',
|
|
278
|
-
} ),
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
|
-
|
|
282
|
-
{
|
|
283
|
-
meta: {
|
|
284
|
-
breakpoint: 'tablet',
|
|
285
|
-
state: null,
|
|
286
|
-
},
|
|
287
|
-
props: {
|
|
288
|
-
'font-size': sizePropTypeUtil.create( {
|
|
289
|
-
size: 18,
|
|
290
|
-
unit: 'px',
|
|
291
|
-
} ),
|
|
292
|
-
},
|
|
293
|
-
},
|
|
294
|
-
|
|
295
|
-
{
|
|
296
|
-
meta: {
|
|
297
|
-
breakpoint: 'mobile',
|
|
298
|
-
state: null,
|
|
299
|
-
},
|
|
300
|
-
props: {
|
|
301
|
-
'font-size': sizePropTypeUtil.create( {
|
|
302
|
-
size: 12,
|
|
303
|
-
unit: 'px',
|
|
304
|
-
} ),
|
|
305
|
-
},
|
|
306
|
-
},
|
|
307
|
-
],
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
// Act.
|
|
311
|
-
const cssString = await render( {
|
|
312
|
-
styles: [ styleDef ],
|
|
313
|
-
transformers,
|
|
314
|
-
breakpoints: mockBreakpoints,
|
|
315
|
-
} );
|
|
316
|
-
|
|
317
|
-
// Assert.
|
|
318
|
-
const defaultStyle = '.test{font-size:24px;}';
|
|
319
|
-
const tabletStyle = '@media(max-width:992px){.test{font-size:18px;}}';
|
|
320
|
-
const mobileStyle = '@media(max-width:768px){.test{font-size:12px;}}';
|
|
321
|
-
|
|
322
|
-
expect( cssString ).toBe(
|
|
323
|
-
`<style data-style-id="test">${ defaultStyle }${ tabletStyle }${ mobileStyle }</style>`
|
|
324
|
-
);
|
|
325
|
-
} );
|
|
326
|
-
|
|
327
|
-
it( 'should render pseudo classes', async () => {
|
|
328
|
-
// Arrange.
|
|
329
|
-
const styleDef: StyleDefinition = {
|
|
330
|
-
id: 'test',
|
|
331
|
-
type: 'class',
|
|
332
|
-
label: 'Test',
|
|
333
|
-
variants: [
|
|
334
|
-
{
|
|
335
|
-
meta: {
|
|
336
|
-
breakpoint: null,
|
|
337
|
-
state: null,
|
|
338
|
-
},
|
|
339
|
-
props: {
|
|
340
|
-
'font-size': sizePropTypeUtil.create( {
|
|
341
|
-
size: 24,
|
|
342
|
-
unit: 'px',
|
|
343
|
-
} ),
|
|
344
|
-
},
|
|
345
|
-
},
|
|
346
|
-
|
|
347
|
-
{
|
|
348
|
-
meta: {
|
|
349
|
-
breakpoint: null,
|
|
350
|
-
state: 'hover',
|
|
351
|
-
},
|
|
352
|
-
props: {
|
|
353
|
-
'font-size': sizePropTypeUtil.create( {
|
|
354
|
-
size: 18,
|
|
355
|
-
unit: 'px',
|
|
356
|
-
} ),
|
|
357
|
-
},
|
|
358
|
-
},
|
|
359
|
-
|
|
360
|
-
{
|
|
361
|
-
meta: {
|
|
362
|
-
breakpoint: 'mobile',
|
|
363
|
-
state: 'focus',
|
|
364
|
-
},
|
|
365
|
-
props: {
|
|
366
|
-
'font-size': sizePropTypeUtil.create( {
|
|
367
|
-
size: 12,
|
|
368
|
-
unit: 'px',
|
|
369
|
-
} ),
|
|
370
|
-
},
|
|
371
|
-
},
|
|
372
|
-
],
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
// Act.
|
|
376
|
-
const cssString = await render( {
|
|
377
|
-
styles: [ styleDef ],
|
|
378
|
-
transformers,
|
|
379
|
-
breakpoints: mockBreakpoints,
|
|
380
|
-
} );
|
|
381
|
-
|
|
382
|
-
// Assert.
|
|
383
|
-
const defaultStyle = '.test{font-size:24px;}';
|
|
384
|
-
const hoverStyle = '.test:hover{font-size:18px;}';
|
|
385
|
-
const focusStyle = '@media(max-width:768px){.test:focus{font-size:12px;}}';
|
|
386
|
-
|
|
387
|
-
expect( cssString ).toBe(
|
|
388
|
-
`<style data-style-id="test">${ defaultStyle }${ hoverStyle }${ focusStyle }</style>`
|
|
389
|
-
);
|
|
390
|
-
} );
|
|
391
|
-
|
|
392
|
-
it( 'should skip disabled props', async () => {
|
|
393
|
-
// Arrange.
|
|
394
|
-
const styleDef = createMockStyleDefinition( {
|
|
395
|
-
id: 'test',
|
|
396
|
-
props: {
|
|
397
|
-
'font-size': sizePropTypeUtil.create( {
|
|
398
|
-
size: 24,
|
|
399
|
-
unit: 'px',
|
|
400
|
-
} ),
|
|
401
|
-
padding: sizePropTypeUtil.create(
|
|
402
|
-
{
|
|
403
|
-
size: 24,
|
|
404
|
-
unit: 'px',
|
|
405
|
-
},
|
|
406
|
-
{ disabled: true }
|
|
407
|
-
),
|
|
408
|
-
},
|
|
409
|
-
} );
|
|
410
|
-
|
|
411
|
-
// Act.
|
|
412
|
-
const cssString = await render( {
|
|
413
|
-
styles: [ styleDef ],
|
|
414
|
-
transformers,
|
|
415
|
-
breakpoints: mockBreakpoints,
|
|
416
|
-
} );
|
|
417
|
-
|
|
418
|
-
// Assert.
|
|
419
|
-
expect( cssString ).toBe( `<style data-style-id="test">.test{font-size:24px;}</style>` );
|
|
420
|
-
} );
|
|
421
|
-
|
|
422
|
-
it( 'should fallback to default value when there is no value', async () => {
|
|
423
|
-
// Arrange.
|
|
424
|
-
const styleDef = createMockStyleDefinition( {
|
|
425
|
-
id: 'test',
|
|
426
|
-
props: {},
|
|
427
|
-
} );
|
|
428
|
-
|
|
429
|
-
jest.mocked( getStylesSchema ).mockReturnValue( {
|
|
430
|
-
overflow: {
|
|
431
|
-
kind: 'plain',
|
|
432
|
-
key: 'string',
|
|
433
|
-
default: {
|
|
434
|
-
$$type: 'string',
|
|
435
|
-
value: 'hidden',
|
|
436
|
-
},
|
|
437
|
-
settings: {},
|
|
438
|
-
meta: {},
|
|
439
|
-
},
|
|
440
|
-
} );
|
|
441
|
-
|
|
442
|
-
// Act.
|
|
443
|
-
const cssString = await render( {
|
|
444
|
-
styles: [ styleDef ],
|
|
445
|
-
transformers,
|
|
446
|
-
breakpoints: mockBreakpoints,
|
|
447
|
-
} );
|
|
448
|
-
|
|
449
|
-
// Assert.
|
|
450
|
-
expect( cssString ).toBe( `<style data-style-id="test">.test{overflow:hidden;}</style>` );
|
|
451
|
-
} );
|
|
452
|
-
|
|
453
|
-
it( 'should skip props that are not in the schema', async () => {
|
|
454
|
-
// Arrange.
|
|
455
|
-
const styleDef = createMockStyleDefinition( {
|
|
456
|
-
id: 'test',
|
|
457
|
-
props: {
|
|
458
|
-
'font-size': sizePropTypeUtil.create( {
|
|
459
|
-
size: 24,
|
|
460
|
-
unit: 'px',
|
|
461
|
-
} ),
|
|
462
|
-
'not-a-css-prop': sizePropTypeUtil.create( {
|
|
463
|
-
size: 24,
|
|
464
|
-
unit: 'px',
|
|
465
|
-
} ),
|
|
466
|
-
},
|
|
467
|
-
} );
|
|
468
|
-
|
|
469
|
-
// Act.
|
|
470
|
-
const cssString = await render( {
|
|
471
|
-
styles: [ styleDef ],
|
|
472
|
-
transformers,
|
|
473
|
-
breakpoints: mockBreakpoints,
|
|
474
|
-
} );
|
|
475
|
-
|
|
476
|
-
// Assert.
|
|
477
|
-
expect( cssString ).toBe( `<style data-style-id="test">.test{font-size:24px;}</style>` );
|
|
478
|
-
} );
|
|
479
|
-
|
|
480
|
-
it( "should skip props that don't have a transformer", async () => {
|
|
481
|
-
// Arrange.
|
|
482
|
-
const styleDef = createMockStyleDefinition( {
|
|
483
|
-
id: 'test',
|
|
484
|
-
props: {
|
|
485
|
-
'font-size': sizePropTypeUtil.create( {
|
|
486
|
-
size: 24,
|
|
487
|
-
unit: 'px',
|
|
488
|
-
} ),
|
|
489
|
-
padding: {
|
|
490
|
-
$$type: 'invalid',
|
|
491
|
-
value: 'invalid',
|
|
492
|
-
},
|
|
493
|
-
},
|
|
494
|
-
} );
|
|
495
|
-
|
|
496
|
-
// Act.
|
|
497
|
-
const cssString = await render( {
|
|
498
|
-
styles: [ styleDef ],
|
|
499
|
-
transformers,
|
|
500
|
-
breakpoints: mockBreakpoints,
|
|
501
|
-
} );
|
|
502
|
-
|
|
503
|
-
// Assert.
|
|
504
|
-
expect( cssString ).toBe( `<style data-style-id="test">.test{font-size:24px;}</style>` );
|
|
505
|
-
} );
|
|
506
|
-
|
|
507
|
-
it( 'should skip props when their transformer throws an error', async () => {
|
|
508
|
-
// Arrange.
|
|
509
|
-
const styleDef = createMockStyleDefinition( {
|
|
510
|
-
id: 'test',
|
|
511
|
-
props: {
|
|
512
|
-
'font-size': '24px',
|
|
513
|
-
padding: sizePropTypeUtil.create( {
|
|
514
|
-
size: 24,
|
|
515
|
-
unit: 'px',
|
|
516
|
-
} ),
|
|
517
|
-
},
|
|
518
|
-
} );
|
|
519
|
-
|
|
520
|
-
// Act.
|
|
521
|
-
const cssString = await render( {
|
|
522
|
-
styles: [ styleDef ],
|
|
523
|
-
transformers: {
|
|
524
|
-
size: () => {
|
|
525
|
-
throw new Error( 'Test error' );
|
|
526
|
-
},
|
|
527
|
-
},
|
|
528
|
-
breakpoints: mockBreakpoints,
|
|
529
|
-
} );
|
|
530
|
-
|
|
531
|
-
// Assert.
|
|
532
|
-
expect( cssString ).toBe( `<style data-style-id="test">.test{font-size:24px;}</style>` );
|
|
533
|
-
} );
|
|
534
|
-
|
|
535
|
-
it( 'should consider 0 as valid value', async () => {
|
|
536
|
-
// Arrange.
|
|
537
|
-
const styleDef = createMockStyleDefinition( {
|
|
538
|
-
id: 'test',
|
|
539
|
-
props: {
|
|
540
|
-
'font-size': sizePropTypeUtil.create( {
|
|
541
|
-
size: 0,
|
|
542
|
-
unit: 'px',
|
|
543
|
-
} ),
|
|
544
|
-
},
|
|
545
|
-
} );
|
|
546
|
-
|
|
547
|
-
// Act.
|
|
548
|
-
const cssString = await render( {
|
|
549
|
-
styles: [ styleDef ],
|
|
550
|
-
transformers,
|
|
551
|
-
breakpoints: mockBreakpoints,
|
|
552
|
-
} );
|
|
553
|
-
|
|
554
|
-
// Assert.
|
|
555
|
-
expect( cssString ).toBe( `<style data-style-id="test">.test{font-size:0px;}</style>` );
|
|
556
|
-
} );
|
|
557
|
-
|
|
558
|
-
it( 'should add selector prefix to the output', async () => {
|
|
559
|
-
// Arrange.
|
|
560
|
-
const styleDef = createMockStyleDefinition( {
|
|
561
|
-
id: 'test',
|
|
562
|
-
props: {
|
|
563
|
-
'font-size': sizePropTypeUtil.create( {
|
|
564
|
-
size: 24,
|
|
565
|
-
unit: 'px',
|
|
566
|
-
} ),
|
|
567
|
-
},
|
|
568
|
-
} );
|
|
569
|
-
|
|
570
|
-
// Act.
|
|
571
|
-
const cssString = await render( {
|
|
572
|
-
styles: [ styleDef ],
|
|
573
|
-
transformers,
|
|
574
|
-
selectorPrefix: '.elementor-prefix',
|
|
575
|
-
breakpoints: mockBreakpoints,
|
|
576
|
-
} );
|
|
577
|
-
|
|
578
|
-
// Assert.
|
|
579
|
-
expect( cssString ).toBe( `<style data-style-id="test">.elementor-prefix .test{font-size:24px;}</style>` );
|
|
580
|
-
} );
|
|
581
|
-
} );
|
|
582
|
-
|
|
583
|
-
const backgroundExpectationWrapper = ( id: string, bgShorthand: string ) => {
|
|
584
|
-
return `<style data-style-id="${ id }">.${ id }{background:${ bgShorthand };}</style>`;
|
|
585
|
-
};
|
|
586
|
-
|
|
587
|
-
describe( 'background-transformer', () => {
|
|
588
|
-
beforeEach( () => {
|
|
589
|
-
jest.mocked( getStylesSchema ).mockReturnValue( stylesSchemaMock );
|
|
590
|
-
} );
|
|
591
|
-
|
|
592
|
-
it( 'should transform background color', async () => {
|
|
593
|
-
// Arrange.
|
|
594
|
-
const styleDef = createMockStyleDefinition( {
|
|
595
|
-
id: 'bg-color',
|
|
596
|
-
props: {
|
|
597
|
-
background: backgroundPropTypeUtil.create( {
|
|
598
|
-
color: colorPropTypeUtil.create( '#ee00ff' ),
|
|
599
|
-
} ),
|
|
600
|
-
},
|
|
601
|
-
} );
|
|
602
|
-
|
|
603
|
-
// Act.
|
|
604
|
-
const cssString = await render( {
|
|
605
|
-
styles: [ styleDef ],
|
|
606
|
-
transformers,
|
|
607
|
-
breakpoints: mockBreakpoints,
|
|
608
|
-
} );
|
|
609
|
-
|
|
610
|
-
// Assert.
|
|
611
|
-
expect( cssString ).toBe( backgroundExpectationWrapper( 'bg-color', '#ee00ff' ) );
|
|
612
|
-
} );
|
|
613
|
-
|
|
614
|
-
it( 'should transform background overlay (repeater)', async () => {
|
|
615
|
-
// Arrange.
|
|
616
|
-
jest.mocked( getMediaAttachment ).mockImplementation( ( args ) => {
|
|
617
|
-
return Promise.resolve( { url: `image-url-${ args.id }` } ) as never;
|
|
618
|
-
} );
|
|
619
|
-
|
|
620
|
-
const styleDef = createMockStyleDefinition( {
|
|
621
|
-
id: 'test',
|
|
622
|
-
props: {
|
|
623
|
-
background: backgroundPropTypeUtil.create( {
|
|
624
|
-
'background-overlay': backgroundOverlayPropTypeUtil.create( [
|
|
625
|
-
backgroundColorOverlayPropTypeUtil.create( 'blue' ),
|
|
626
|
-
backgroundColorOverlayPropTypeUtil.create( 'yellow' ),
|
|
627
|
-
backgroundImageOverlayPropTypeUtil.create( {
|
|
628
|
-
'image-src': imageSrcPropTypeUtil.create( {
|
|
629
|
-
id: imageAttachmentIdPropType.create( 123 ),
|
|
630
|
-
url: null,
|
|
631
|
-
} ),
|
|
632
|
-
size: 'contain',
|
|
633
|
-
} ),
|
|
634
|
-
backgroundImageOverlayPropTypeUtil.create( {
|
|
635
|
-
'image-src': imageSrcPropTypeUtil.create( {
|
|
636
|
-
id: imageAttachmentIdPropType.create( 123 ),
|
|
637
|
-
url: null,
|
|
638
|
-
} ),
|
|
639
|
-
size: 'auto',
|
|
640
|
-
position: 'center right',
|
|
641
|
-
repeat: 'repeat-x',
|
|
642
|
-
attachment: 'fixed',
|
|
643
|
-
} ),
|
|
644
|
-
] ),
|
|
645
|
-
} ),
|
|
646
|
-
},
|
|
647
|
-
} );
|
|
648
|
-
|
|
649
|
-
// Act.
|
|
650
|
-
const cssString = await render( {
|
|
651
|
-
styles: [ styleDef ],
|
|
652
|
-
transformers,
|
|
653
|
-
breakpoints: mockBreakpoints,
|
|
654
|
-
} );
|
|
655
|
-
|
|
656
|
-
// Assert.
|
|
657
|
-
expect( cssString ).toBe(
|
|
658
|
-
backgroundExpectationWrapper(
|
|
659
|
-
'test',
|
|
660
|
-
'linear-gradient(blue, blue),linear-gradient(yellow, yellow),url(image-url-123) 0% 0% / contain,url(image-url-123) repeat-x fixed center right / auto'
|
|
661
|
-
)
|
|
662
|
-
);
|
|
663
|
-
} );
|
|
664
|
-
|
|
665
|
-
it( 'should transform background (including also background-overlay & color)', async () => {
|
|
666
|
-
// Arrange.
|
|
667
|
-
jest.mocked( getMediaAttachment ).mockImplementation( ( args ) => {
|
|
668
|
-
return Promise.resolve( { url: `image-url-${ args.id }` } ) as never;
|
|
669
|
-
} );
|
|
670
|
-
|
|
671
|
-
const styleDef = createMockStyleDefinition( {
|
|
672
|
-
id: 'test',
|
|
673
|
-
props: {
|
|
674
|
-
background: backgroundPropTypeUtil.create( {
|
|
675
|
-
color: colorPropTypeUtil.create( '#000' ),
|
|
676
|
-
'background-overlay': backgroundOverlayPropTypeUtil.create( [
|
|
677
|
-
backgroundColorOverlayPropTypeUtil.create( '#FFFFFF' ),
|
|
678
|
-
backgroundColorOverlayPropTypeUtil.create( '#FF2222' ),
|
|
679
|
-
backgroundImageOverlayPropTypeUtil.create( {
|
|
680
|
-
'image-src': imageSrcPropTypeUtil.create( {
|
|
681
|
-
id: imageAttachmentIdPropType.create( 123 ),
|
|
682
|
-
url: null,
|
|
683
|
-
} ),
|
|
684
|
-
size: 'contain',
|
|
685
|
-
} ),
|
|
686
|
-
backgroundImageOverlayPropTypeUtil.create( {
|
|
687
|
-
'image-src': imageSrcPropTypeUtil.create( {
|
|
688
|
-
id: imageAttachmentIdPropType.create( 123 ),
|
|
689
|
-
url: null,
|
|
690
|
-
} ),
|
|
691
|
-
size: 'auto',
|
|
692
|
-
position: 'center right',
|
|
693
|
-
repeat: 'repeat-y',
|
|
694
|
-
attachment: 'fixed',
|
|
695
|
-
} ),
|
|
696
|
-
] ),
|
|
697
|
-
} ),
|
|
698
|
-
},
|
|
699
|
-
} );
|
|
700
|
-
|
|
701
|
-
// Act.
|
|
702
|
-
const cssString = await render( {
|
|
703
|
-
styles: [ styleDef ],
|
|
704
|
-
transformers,
|
|
705
|
-
breakpoints: mockBreakpoints,
|
|
706
|
-
} );
|
|
707
|
-
|
|
708
|
-
// Assert.
|
|
709
|
-
expect( cssString ).toBe(
|
|
710
|
-
backgroundExpectationWrapper(
|
|
711
|
-
'test',
|
|
712
|
-
'linear-gradient(#FFFFFF, #FFFFFF),linear-gradient(#FF2222, #FF2222),url(image-url-123) 0% 0% / contain,url(image-url-123) repeat-y fixed center right / auto #000'
|
|
713
|
-
)
|
|
714
|
-
);
|
|
715
|
-
} );
|
|
716
|
-
} );
|
|
717
|
-
|
|
718
|
-
describe( 'background-overlay-transformer', () => {
|
|
719
|
-
it( 'should return empty if background-overlay is invalid', () => {
|
|
720
|
-
// Arrange.
|
|
721
|
-
const initialData = {
|
|
722
|
-
'background-overlay': null,
|
|
723
|
-
};
|
|
724
|
-
|
|
725
|
-
// Act.
|
|
726
|
-
const result = backgroundTransformer( initialData, { key: 'background-overlay' } );
|
|
727
|
-
|
|
728
|
-
// Assert.
|
|
729
|
-
expect( result ).toBe( '' );
|
|
730
|
-
} );
|
|
731
|
-
|
|
732
|
-
it( 'should transform only valid background color', () => {
|
|
733
|
-
// Arrange.
|
|
734
|
-
const backgroundColor = 'rgba(255, 0, 255, 0.9)';
|
|
735
|
-
|
|
736
|
-
const initialData = {
|
|
737
|
-
color: backgroundColor,
|
|
738
|
-
};
|
|
739
|
-
|
|
740
|
-
// Act.
|
|
741
|
-
const result = backgroundTransformer( initialData, { key: 'background-overlay' } );
|
|
742
|
-
|
|
743
|
-
// Assert.
|
|
744
|
-
expect( result ).toBe( backgroundColor );
|
|
745
|
-
} );
|
|
746
|
-
|
|
747
|
-
it( 'should transform only background overlay color', () => {
|
|
748
|
-
// Arrange.
|
|
749
|
-
const backgroundOverlayColor = 'rgba(0, 0, 0, 0.5)';
|
|
750
|
-
const expected = `linear-gradient(${ backgroundOverlayColor }, ${ backgroundOverlayColor })`;
|
|
751
|
-
|
|
752
|
-
const initialData = {
|
|
753
|
-
'background-overlay': `linear-gradient(${ backgroundOverlayColor }, ${ backgroundOverlayColor })`,
|
|
754
|
-
};
|
|
755
|
-
|
|
756
|
-
// Act.
|
|
757
|
-
const result = backgroundTransformer( initialData, { key: 'background-overlay' } );
|
|
758
|
-
|
|
759
|
-
// Assert.
|
|
760
|
-
expect( result ).toBe( expected );
|
|
761
|
-
} );
|
|
762
|
-
} );
|
|
763
|
-
|
|
764
|
-
const mockBreakpoints = {
|
|
765
|
-
tablet: {
|
|
766
|
-
id: 'tablet',
|
|
767
|
-
width: 992,
|
|
768
|
-
label: 'Tablet Portrait',
|
|
769
|
-
type: 'max-width',
|
|
770
|
-
},
|
|
771
|
-
mobile: {
|
|
772
|
-
id: 'mobile',
|
|
773
|
-
width: 768,
|
|
774
|
-
label: 'Mobile Portrait',
|
|
775
|
-
type: 'max-width',
|
|
776
|
-
},
|
|
777
|
-
} as BreakpointsMap;
|