| 1 |
( function () { |
| 2 |
var el = React.createElement; |
| 3 |
var registerBlockType = wp.blocks.registerBlockType; |
| 4 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 5 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 6 |
var PanelBody = wp.components.PanelBody; |
| 7 |
var ToggleControl = wp.components.ToggleControl; |
| 8 |
var RangeControl = wp.components.RangeControl; |
| 9 |
var SelectControl = wp.components.SelectControl; |
| 10 |
var TextControl = wp.components.TextControl; |
| 11 |
var TextareaControl = wp.components.TextareaControl; |
| 12 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 13 |
|
| 14 |
/* ── typography lazy-getters ── */ |
| 15 |
function _tc() { return window.bkbgTypographyControl || null; } |
| 16 |
function _tv() { return window.bkbgTypoCssVars || function () { return {}; }; } |
| 17 |
|
| 18 |
var ANIM_TYPES = [ |
| 19 |
{ value: 'shift', label: 'Shift — gradient slides' }, |
| 20 |
{ value: 'pulse', label: 'Pulse — gradient breathes' }, |
| 21 |
{ value: 'wave', label: 'Wave — per-character wave' }, |
| 22 |
{ value: 'rainbow', label: 'Rainbow — full spectrum cycle' }, |
| 23 |
{ value: 'reveal', label: 'Reveal — sweeping spotlight' }, |
| 24 |
{ value: 'glitch', label: 'Glitch — RGB displacement' } |
| 25 |
]; |
| 26 |
|
| 27 |
var DIRECTIONS = [ |
| 28 |
{ value: 'horizontal', label: 'Horizontal →' }, |
| 29 |
{ value: 'diagonal', label: 'Diagonal ↘' }, |
| 30 |
{ value: 'radial', label: 'Radial ○' } |
| 31 |
]; |
| 32 |
|
| 33 |
var TAGS = [ |
| 34 |
{ value: 'h1', label: 'H1' }, { value: 'h2', label: 'H2' }, |
| 35 |
{ value: 'h3', label: 'H3' }, { value: 'h4', label: 'H4' }, |
| 36 |
{ value: 'h5', label: 'H5' }, { value: 'h6', label: 'H6' }, |
| 37 |
{ value: 'p', label: 'P (paragraph)' }, |
| 38 |
{ value: 'div',label: 'div' } |
| 39 |
]; |
| 40 |
|
| 41 |
var WEIGHTS = [ |
| 42 |
{ value: '300', label: 'Light 300' }, { value: '400', label: 'Regular 400' }, |
| 43 |
{ value: '600', label: 'SemiBold 600' }, { value: '700', label: 'Bold 700' }, |
| 44 |
{ value: '800', label: 'ExtraBold 800' }, { value: '900', label: 'Black 900' } |
| 45 |
]; |
| 46 |
|
| 47 |
var FONT_FAMILIES = [ |
| 48 |
{ value: 'inherit', label: 'Theme Default' }, |
| 49 |
{ value: 'serif', label: 'Serif' }, |
| 50 |
{ value: 'sans-serif', label: 'Sans-Serif' }, |
| 51 |
{ value: 'monospace', label: 'Monospace' }, |
| 52 |
{ value: 'Georgia, serif', label: 'Georgia' }, |
| 53 |
{ value: "'Playfair Display', Georgia, serif", label: 'Playfair Display' }, |
| 54 |
{ value: "'Oswald', sans-serif", label: 'Oswald' } |
| 55 |
]; |
| 56 |
|
| 57 |
function buildGradientCss(attr) { |
| 58 |
var colors = [attr.color1, attr.color2]; |
| 59 |
if (attr.stopCount >= 3) colors.push(attr.color3); |
| 60 |
if (attr.stopCount >= 4) colors.push(attr.color4); |
| 61 |
var dir = attr.direction === 'radial' ? 'circle' |
| 62 |
: attr.direction === 'diagonal' ? '135deg' : '90deg'; |
| 63 |
if (attr.direction === 'radial') { |
| 64 |
return 'radial-gradient(' + dir + ', ' + colors.join(', ') + ')'; |
| 65 |
} |
| 66 |
return 'linear-gradient(' + dir + ', ' + colors.join(', ') + ')'; |
| 67 |
} |
| 68 |
|
| 69 |
function GradientTextPreview(props) { |
| 70 |
var attr = props.attr; |
| 71 |
var gradCss = buildGradientCss(attr); |
| 72 |
var animClass = 'bkbg-gta-anim-' + (attr.animationType || 'shift'); |
| 73 |
var speed = (attr.animationSpeed || 4) + 's'; |
| 74 |
|
| 75 |
var textStyle = { |
| 76 |
textAlign: attr.textAlign || 'center', |
| 77 |
background: gradCss, |
| 78 |
backgroundSize: attr.animationType === 'shift' || attr.animationType === 'rainbow' ? '300% 300%' : '200% 200%', |
| 79 |
WebkitBackgroundClip: 'text', |
| 80 |
backgroundClip: 'text', |
| 81 |
WebkitTextFillColor: 'transparent', |
| 82 |
color: 'transparent', |
| 83 |
margin: 0, |
| 84 |
padding: 0, |
| 85 |
display: 'inline-block', |
| 86 |
width: '100%' |
| 87 |
}; |
| 88 |
|
| 89 |
if (attr.glowEffect) { |
| 90 |
textStyle.filter = 'drop-shadow(0 0 ' + (attr.glowBlur || 20) + 'px ' + attr.color1 + ')'; |
| 91 |
} |
| 92 |
|
| 93 |
return el('div', { |
| 94 |
className: 'bkbg-gta-app', |
| 95 |
style: { |
| 96 |
padding: (attr.paddingV || 24) + 'px ' + (attr.paddingH || 24) + 'px', |
| 97 |
backgroundColor: attr.showBg ? (attr.bgColor || '#0f172a') : 'transparent', |
| 98 |
borderRadius: (attr.borderRadius || 0) + 'px', |
| 99 |
textAlign: attr.textAlign || 'center', |
| 100 |
overflow: 'hidden' |
| 101 |
} |
| 102 |
}, |
| 103 |
el(attr.tag || 'h2', { |
| 104 |
className: 'bkbg-gta-el ' + animClass, |
| 105 |
style: Object.assign(textStyle, { animationDuration: speed }) |
| 106 |
}, attr.text || 'Animated Gradient Text') |
| 107 |
); |
| 108 |
} |
| 109 |
|
| 110 |
registerBlockType('blockenberg/gradient-text-animator', { |
| 111 |
title: 'Gradient Text Animator', |
| 112 |
icon: 'editor-textcolor', |
| 113 |
category: 'bkbg-effects', |
| 114 |
|
| 115 |
edit: function (props) { |
| 116 |
var attr = props.attributes; |
| 117 |
var setAttr = props.setAttributes; |
| 118 |
|
| 119 |
return el(React.Fragment, null, |
| 120 |
el(InspectorControls, null, |
| 121 |
// Text |
| 122 |
el(PanelBody, { title: 'Text Content', initialOpen: true }, |
| 123 |
el(TextareaControl, { __nextHasNoMarginBottom: true, label: 'Text', value: attr.text, onChange: function (v) { setAttr({ text: v }); } }), |
| 124 |
el(SelectControl, { __nextHasNoMarginBottom: true, label: 'HTML Tag', value: attr.tag, options: TAGS, onChange: function (v) { setAttr({ tag: v }); } }), |
| 125 |
el(SelectControl, { __nextHasNoMarginBottom: true, label: 'Text Align', value: attr.textAlign, options: [{value:'left',label:'Left'},{value:'center',label:'Center'},{value:'right',label:'Right'}], onChange: function (v) { setAttr({ textAlign: v }); } }) |
| 126 |
), |
| 127 |
// Typography |
| 128 |
el(PanelBody, { title: 'Typography', initialOpen: false }, |
| 129 |
_tc() && el(_tc(), { label:'Text', value:attr.typoText, onChange:function(v){ setAttr({typoText:v}); } }) |
| 130 |
), |
| 131 |
// Animation |
| 132 |
el(PanelBody, { title: 'Animation', initialOpen: true }, |
| 133 |
el(SelectControl, { __nextHasNoMarginBottom: true, label: 'Animation Type', value: attr.animationType, options: ANIM_TYPES, onChange: function (v) { setAttr({ animationType: v }); } }), |
| 134 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Speed (seconds per cycle)', value: attr.animationSpeed, min: 0.5, max: 20, step: 0.5, onChange: function (v) { setAttr({ animationSpeed: v }); } }), |
| 135 |
el(SelectControl, { __nextHasNoMarginBottom: true, label: 'Direction', value: attr.direction, options: DIRECTIONS, onChange: function (v) { setAttr({ direction: v }); } }), |
| 136 |
el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Pause on Hover', checked: attr.pauseOnHover, onChange: function (v) { setAttr({ pauseOnHover: v }); } }), |
| 137 |
el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Reverse on Hover', checked: attr.reverseOnHover, onChange: function (v) { setAttr({ reverseOnHover: v }); } }) |
| 138 |
), |
| 139 |
// Glow |
| 140 |
el(PanelBody, { title: 'Glow Effect', initialOpen: false }, |
| 141 |
el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Enable Glow', checked: attr.glowEffect, onChange: function (v) { setAttr({ glowEffect: v }); } }), |
| 142 |
attr.glowEffect && el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Glow Blur (px)', value: attr.glowBlur, min: 4, max: 80, onChange: function (v) { setAttr({ glowBlur: v }); } }), |
| 143 |
attr.glowEffect && el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Glow Opacity', value: attr.glowOpacity, min: 0.1, max: 1, step: 0.05, onChange: function (v) { setAttr({ glowOpacity: v }); } }) |
| 144 |
), |
| 145 |
// Background |
| 146 |
el(PanelBody, { title: 'Background', initialOpen: false }, |
| 147 |
el(ToggleControl, { __nextHasNoMarginBottom: true, label: 'Show Background', checked: attr.showBg, onChange: function (v) { setAttr({ showBg: v }); } }), |
| 148 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Padding Vertical (px)', value: attr.paddingV, min: 0, max: 120, onChange: function (v) { setAttr({ paddingV: v }); } }), |
| 149 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Padding Horizontal (px)', value: attr.paddingH, min: 0, max: 120, onChange: function (v) { setAttr({ paddingH: v }); } }), |
| 150 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Border Radius (px)', value: attr.borderRadius, min: 0, max: 60, onChange: function (v) { setAttr({ borderRadius: v }); } }) |
| 151 |
), |
| 152 |
el(PanelColorSettings, { |
| 153 |
title: 'Gradient Colors', |
| 154 |
initialOpen: false, |
| 155 |
colorSettings: [ |
| 156 |
{ value: attr.color1, onChange: function (v) { setAttr({ color1: v || '#f59e0b' }); }, label: 'Color 1' }, |
| 157 |
{ value: attr.color2, onChange: function (v) { setAttr({ color2: v || '#ec4899' }); }, label: 'Color 2' }, |
| 158 |
{ value: attr.color3, onChange: function (v) { setAttr({ color3: v || '#8b5cf6' }); }, label: 'Color 3 (3+ stops)' }, |
| 159 |
{ value: attr.color4, onChange: function (v) { setAttr({ color4: v || '#06b6d4' }); }, label: 'Color 4 (4 stops)' }, |
| 160 |
attr.showBg && { value: attr.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#0f172a' }); }, label: 'Background Color' } |
| 161 |
].filter(Boolean) |
| 162 |
}), |
| 163 |
el(PanelBody, { title: 'Color Stops', initialOpen: false }, |
| 164 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: 'Number of Color Stops', value: attr.stopCount, min: 2, max: 4, onChange: function (v) { setAttr({ stopCount: v }); } }) |
| 165 |
) |
| 166 |
), |
| 167 |
|
| 168 |
el('div', useBlockProps({ style: _tv()(attr.typoText, '--bkbg-gta-tt-') }), |
| 169 |
el(GradientTextPreview, { attr: attr }) |
| 170 |
) |
| 171 |
); |
| 172 |
}, |
| 173 |
|
| 174 |
save: function (props) { |
| 175 |
var attr = props.attributes; |
| 176 |
return el('div', useBlockProps.save(), |
| 177 |
el('div', { |
| 178 |
className: 'bkbg-gta-app', |
| 179 |
'data-opts': JSON.stringify(attr) |
| 180 |
}) |
| 181 |
); |
| 182 |
} |
| 183 |
}); |
| 184 |
}() ); |
| 185 |
|