PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.13
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.13
2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / text-gradient / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.13, at blocks/text-gradient/index.js

230 lines 12.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 var el = wp.element.createElement;
3 var __ = wp.i18n.__;
4 var registerBlockType = wp.blocks.registerBlockType;
5 var InspectorControls = wp.blockEditor.InspectorControls;
6 var RichText = wp.blockEditor.RichText;
7 var useBlockProps = wp.blockEditor.useBlockProps;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var PanelBody = wp.components.PanelBody;
10 var ToggleControl = wp.components.ToggleControl;
11 var RangeControl = wp.components.RangeControl;
12 var SelectControl = wp.components.SelectControl;
13
14 var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
15 var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
16
17 var TAG_OPTIONS = [
18 { label: 'H1', value: 'h1' }, { label: 'H2', value: 'h2' },
19 { label: 'H3', value: 'h3' }, { label: 'H4', value: 'h4' },
20 { label: 'H5', value: 'h5' }, { label: 'H6', value: 'h6' },
21 { label: 'p', value: 'p' }, { label: 'span / div', value: 'div' },
22 ];
23 var ALIGN_OPTIONS = [
24 { label: 'Left', value: 'left' }, { label: 'Center', value: 'center' }, { label: 'Right', value: 'right' }
25 ];
26 var WEIGHT_OPTIONS = [
27 { label: '300 — Light', value: 300 }, { label: '400 — Regular', value: 400 },
28 { label: '500 — Medium', value: 500 }, { label: '600 — SemiBold', value: 600 },
29 { label: '700 — Bold', value: 700 }, { label: '800 — ExtraBold', value: 800 },
30 { label: '900 — Black', value: 900 },
31 ];
32
33 function buildGradient(a) {
34 var stops = a.color1 + ' ' + a.color1Stop + '%';
35 if (a.useColor3) stops += ', ' + a.color3 + ' ' + a.color3Stop + '%';
36 stops += ', ' + a.color2 + ' ' + a.color2Stop + '%';
37 return 'linear-gradient(' + a.gradientAngle + 'deg, ' + stops + ')';
38 }
39
40 function buildTextStyle(a) {
41 var grad = buildGradient(a);
42 var style = {
43 '--bktgr-gradient': grad,
44 '--bktgr-speed': a.animationSpeed + 's',
45 textAlign: a.textAlign,
46 backgroundImage: grad,
47 WebkitBackgroundClip: 'text',
48 backgroundClip: 'text',
49 WebkitTextFillColor: 'transparent',
50 backgroundSize: a.animate ? '200% 200%' : '100% 100%',
51 display: 'inline-block',
52 padding: a.padding + 'px 2px',
53 };
54 if (a.showOutline) {
55 style.WebkitTextStroke = a.outlineWidth + 'px ' + a.outlineColor;
56 }
57 if (a.showShadow) {
58 style.filter = 'drop-shadow(' + a.shadowX + 'px ' + a.shadowY + 'px ' + a.shadowBlur + 'px ' + a.shadowColor + ')';
59 }
60 if (a.animate) {
61 style.animation = 'bktgrShift var(--bktgr-speed, 4s) ease infinite alternate';
62 }
63 return style;
64 }
65
66 registerBlockType('blockenberg/text-gradient', {
67 edit: function (props) {
68 var a = props.attributes;
69 var set = props.setAttributes;
70 var blockProps = useBlockProps((function () {
71 var s = { textAlign: a.textAlign, padding: a.padding + 'px 0' };
72 var _tvf = getTypoCssVars();
73 if (_tvf) { Object.assign(s, _tvf(a.titleTypo, '--bktgr-tt-'), _tvf(a.subtextTypo, '--bktgr-st-')); }
74 return { style: s };
75 })());
76
77 return el('div', blockProps,
78 el(InspectorControls, null,
79 el(PanelBody, { title: __('General', 'blockenberg'), initialOpen: true },
80 el(SelectControl, {
81 label: __('HTML Tag', 'blockenberg'), value: a.tag, options: TAG_OPTIONS,
82 onChange: function (v) { set({ tag: v }); }
83 }),
84 el(SelectControl, {
85 label: __('Text Align', 'blockenberg'), value: a.textAlign, options: ALIGN_OPTIONS,
86 onChange: function (v) { set({ textAlign: v }); }
87 }),
88 el(RangeControl, {
89 label: __('Padding (px)', 'blockenberg'), value: a.padding, min: 0, max: 60,
90 onChange: function (v) { set({ padding: v }); }
91 }),
92 ),
93 el(PanelBody, { title: __('Gradient', 'blockenberg'), initialOpen: false },
94 el(RangeControl, {
95 label: __('Gradient Angle °', 'blockenberg'), value: a.gradientAngle, min: 0, max: 360,
96 onChange: function (v) { set({ gradientAngle: v }); }
97 }),
98 el(ToggleControl, {
99 label: __('Use 3rd Color Stop', 'blockenberg'), checked: a.useColor3,
100 onChange: function (v) { set({ useColor3: v }); }, __nextHasNoMarginBottom: true
101 }),
102 el(ToggleControl, {
103 label: __('Animate Gradient', 'blockenberg'), checked: a.animate,
104 onChange: function (v) { set({ animate: v }); }, __nextHasNoMarginBottom: true
105 }),
106 a.animate && el(RangeControl, {
107 label: __('Animation Speed (s)', 'blockenberg'), value: a.animationSpeed, min: 1, max: 20,
108 onChange: function (v) { set({ animationSpeed: v }); }
109 }),
110 ),
111 el(PanelBody, { title: __('Outline & Shadow', 'blockenberg'), initialOpen: false },
112 el(ToggleControl, {
113 label: __('Text Outline', 'blockenberg'), checked: a.showOutline,
114 onChange: function (v) { set({ showOutline: v }); }, __nextHasNoMarginBottom: true
115 }),
116 a.showOutline && el(RangeControl, {
117 label: __('Outline Width (px)', 'blockenberg'), value: a.outlineWidth, min: 1, max: 8,
118 onChange: function (v) { set({ outlineWidth: v }); }
119 }),
120 el(ToggleControl, {
121 label: __('Drop Shadow', 'blockenberg'), checked: a.showShadow,
122 onChange: function (v) { set({ showShadow: v }); }, __nextHasNoMarginBottom: true
123 }),
124 a.showShadow && el(RangeControl, {
125 label: __('Shadow X (px)', 'blockenberg'), value: a.shadowX, min: -20, max: 20,
126 onChange: function (v) { set({ shadowX: v }); }
127 }),
128 a.showShadow && el(RangeControl, {
129 label: __('Shadow Y (px)', 'blockenberg'), value: a.shadowY, min: -20, max: 20,
130 onChange: function (v) { set({ shadowY: v }); }
131 }),
132 a.showShadow && el(RangeControl, {
133 label: __('Shadow Blur (px)', 'blockenberg'), value: a.shadowBlur, min: 0, max: 60,
134 onChange: function (v) { set({ shadowBlur: v }); }
135 }),
136 ),
137 el(PanelBody, { title: __('Subtext', 'blockenberg'), initialOpen: false },
138 el(ToggleControl, {
139 label: __('Show Subtext', 'blockenberg'), checked: a.showSubtext,
140 onChange: function (v) { set({ showSubtext: v }); }, __nextHasNoMarginBottom: true
141 }),
142 ),
143 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
144 getTypoControl() && getTypoControl()({
145 label: __('Gradient Text', 'blockenberg'),
146 value: a.titleTypo || {},
147 onChange: function (v) { set({ titleTypo: v }); }
148 }),
149 a.showSubtext && getTypoControl() && getTypoControl()({
150 label: __('Subtext', 'blockenberg'),
151 value: a.subtextTypo || {},
152 onChange: function (v) { set({ subtextTypo: v }); }
153 }),
154 ),
155 el(PanelColorSettings, {
156 title: __('Colors', 'blockenberg'), initialOpen: false,
157 colorSettings: [
158 { label: __('Color 1', 'blockenberg'), value: a.color1, onChange: function (v) { set({ color1: v || '#6c3fb5' }); } },
159 { label: __('Color 2', 'blockenberg'), value: a.color2, onChange: function (v) { set({ color2: v || '#ec4899' }); } },
160 a.useColor3 && { label: __('Color 3 (mid)', 'blockenberg'), value: a.color3, onChange: function (v) { set({ color3: v || '#f59e0b' }); } },
161 a.showOutline && { label: __('Outline Color', 'blockenberg'), value: a.outlineColor, onChange: function (v) { set({ outlineColor: v || '#6c3fb5' }); } },
162 a.showShadow && { label: __('Shadow Color', 'blockenberg'), value: a.shadowColor, onChange: function (v) { set({ shadowColor: v || 'rgba(108,63,181,0.35)' }); } },
163 a.showSubtext && { label: __('Subtext Color', 'blockenberg'), value: a.subtextColor, onChange: function (v) { set({ subtextColor: v || '#6b7280' }); } },
164 ].filter(Boolean)
165 }),
166 ),
167 el('div', { style: { textAlign: a.textAlign } },
168 el(RichText, {
169 tagName: a.tag,
170 className: 'bktgr-text',
171 value: a.text,
172 onChange: function (v) { set({ text: v }); },
173 placeholder: __('Your gradient text here…', 'blockenberg'),
174 style: buildTextStyle(a),
175 allowedFormats: [],
176 }),
177 a.showSubtext && el(RichText, {
178 tagName: 'p',
179 className: 'bktgr-sub',
180 value: a.subtext,
181 onChange: function (v) { set({ subtext: v }); },
182 placeholder: __('Subtitle or description…', 'blockenberg'),
183 style: { color: a.subtextColor, marginTop: '12px' },
184 }),
185 ),
186 );
187 },
188
189 save: function (props) {
190 var a = props.attributes;
191 var _tvf = getTypoCssVars();
192 var grad = buildGradient(a);
193 var textStyle = {
194 '--bktgr-gradient': grad,
195 '--bktgr-speed': a.animationSpeed + 's',
196 textAlign: a.textAlign,
197 backgroundImage: grad,
198 WebkitBackgroundClip: 'text',
199 backgroundClip: 'text',
200 WebkitTextFillColor: 'transparent',
201 backgroundSize: a.animate ? '200% 200%' : '100% 100%',
202 display: 'inline-block',
203 padding: a.padding + 'px 2px',
204 };
205 if (a.showOutline) textStyle.WebkitTextStroke = a.outlineWidth + 'px ' + a.outlineColor;
206 if (a.showShadow) textStyle.filter = 'drop-shadow(' + a.shadowX + 'px ' + a.shadowY + 'px ' + a.shadowBlur + 'px ' + a.shadowColor + ')';
207 if (a.animate) textStyle.animation = 'bktgrShift var(--bktgr-speed, 4s) ease infinite alternate';
208
209 return el('div', useBlockProps.save((function () {
210 var s = { textAlign: a.textAlign, padding: a.padding + 'px 0' };
211 if (_tvf) { Object.assign(s, _tvf(a.titleTypo, '--bktgr-tt-'), _tvf(a.subtextTypo, '--bktgr-st-')); }
212 return { className: 'bktgr-wrap', style: s };
213 })()),
214 el(RichText.Content, { tagName: a.tag, value: a.text, className: 'bktgr-text', style: textStyle }),
215 a.showSubtext && el(RichText.Content, {
216 tagName: 'p', value: a.subtext, className: 'bktgr-sub',
217 style: { color: a.subtextColor, marginTop: '12px' }
218 }),
219 );
220
221 function buildGradient(a) {
222 var stops = a.color1 + ' ' + a.color1Stop + '%';
223 if (a.useColor3) stops += ', ' + a.color3 + ' ' + a.color3Stop + '%';
224 stops += ', ' + a.color2 + ' ' + a.color2Stop + '%';
225 return 'linear-gradient(' + a.gradientAngle + 'deg, ' + stops + ')';
226 }
227 }
228 });
229 }() );
230