jetformbuilder
/
modules
/
jet-style
/
assets-src
/
js
/
editor
/
abstract
/
BorderRadiusCSSCompiler.js
BaseCSSCompiler.js
2 years ago
BorderCSSCompiler.js
2 years ago
BorderRadiusCSSCompiler.js
2 years ago
BorderRadiusCSSCompiler.js
81 lines
| 1 | import BaseCSSCompiler from './BaseCSSCompiler'; |
| 2 | |
| 3 | const { get } = window._; |
| 4 | |
| 5 | const { |
| 6 | isEmpty, |
| 7 | } = JetFBActions; |
| 8 | |
| 9 | function BorderRadiusCSSCompiler() { |
| 10 | BaseCSSCompiler.call( this ); |
| 11 | |
| 12 | this.isSupported = function ( path ) { |
| 13 | return ( |
| 14 | 'border' === path.at( 1 ) && |
| 15 | 'radius' === path.at( -1 ) |
| 16 | ); |
| 17 | }; |
| 18 | |
| 19 | this.compileDeclarations = function ( |
| 20 | styleRoot, declarations, classNames ) { |
| 21 | const baseRadius = get( styleRoot, this.path ); |
| 22 | |
| 23 | if ( isEmpty( baseRadius ) ) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | const topLeft = this.getTopLeft( baseRadius ); |
| 28 | |
| 29 | if ( topLeft ) { |
| 30 | declarations[ `${ this.cssVar }-top-left` ] = topLeft; |
| 31 | } |
| 32 | |
| 33 | const topRight = this.getTopRight( baseRadius ); |
| 34 | |
| 35 | if ( topRight ) { |
| 36 | declarations[ `${ this.cssVar }-top-right` ] = topRight; |
| 37 | } |
| 38 | |
| 39 | const bottomRight = this.getBottomRight( baseRadius ); |
| 40 | |
| 41 | if ( bottomRight ) { |
| 42 | declarations[ `${ this.cssVar }-bottom-right` ] = bottomRight; |
| 43 | } |
| 44 | |
| 45 | const bottomLeft = this.getBottomLeft( baseRadius ); |
| 46 | |
| 47 | if ( bottomLeft ) { |
| 48 | declarations[ `${ this.cssVar }-bottom-left` ] = bottomLeft; |
| 49 | } |
| 50 | }; |
| 51 | } |
| 52 | |
| 53 | BorderRadiusCSSCompiler.prototype = Object.create( |
| 54 | BaseCSSCompiler.prototype, |
| 55 | ); |
| 56 | |
| 57 | BorderRadiusCSSCompiler.prototype.isLinked = function ( value ) { |
| 58 | const [ firstKey ] = Object.keys( value ); |
| 59 | |
| 60 | return [ 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' ].includes( |
| 61 | firstKey, |
| 62 | ); |
| 63 | }; |
| 64 | |
| 65 | BorderRadiusCSSCompiler.prototype.getTopLeft = function ( value ) { |
| 66 | return this.isLinked( value ) ? value?.topLeft : value; |
| 67 | }; |
| 68 | |
| 69 | BorderRadiusCSSCompiler.prototype.getTopRight = function ( value ) { |
| 70 | return this.isLinked( value ) ? value?.topRight : value; |
| 71 | }; |
| 72 | |
| 73 | BorderRadiusCSSCompiler.prototype.getBottomLeft = function ( value ) { |
| 74 | return this.isLinked( value ) ? value?.bottomLeft : value; |
| 75 | }; |
| 76 | |
| 77 | BorderRadiusCSSCompiler.prototype.getBottomRight = function ( value ) { |
| 78 | return this.isLinked( value ) ? value?.bottomRight : value; |
| 79 | }; |
| 80 | |
| 81 | export default BorderRadiusCSSCompiler; |