PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.7
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.7
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-stroke / index.js

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

301 lines 15.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 Fragment = wp.element.Fragment;
4 var registerBlockType = wp.blocks.registerBlockType;
5 var __ = wp.i18n.__;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
8 var useBlockProps = wp.blockEditor.useBlockProps;
9 var PanelBody = wp.components.PanelBody;
10 var TextControl = wp.components.TextControl;
11 var TextareaControl = wp.components.TextareaControl;
12 var ToggleControl = wp.components.ToggleControl;
13 var RangeControl = wp.components.RangeControl;
14 var SelectControl = wp.components.SelectControl;
15
16 var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
17 var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
18 var _tvf = function (typo, prefix) { var fn = getTypoCssVars(); return fn ? fn(typo, prefix) : {}; };
19
20 var HOVER_OPTIONS = [
21 { label: __('Fill text on hover', 'blockenberg'), value: 'fill' },
22 { label: __('Change stroke color on hover', 'blockenberg'), value: 'stroke' },
23 { label: __('Scale up on hover', 'blockenberg'), value: 'scale' },
24 { label: __('None', 'blockenberg'), value: 'none' },
25 ];
26
27 var TAG_OPTIONS = [
28 { label: 'h1', value: 'h1' },
29 { label: 'h2', value: 'h2' },
30 { label: 'h3', value: 'h3' },
31 { label: 'h4', value: 'h4' },
32 { label: 'p', value: 'p' },
33 { label: 'div', value: 'div' },
34 ];
35
36 var WEIGHT_OPTIONS = [
37 { label: '400 – Regular', value: '400' },
38 { label: '500 – Medium', value: '500' },
39 { label: '600 – Semi-bold', value: '600' },
40 { label: '700 – Bold', value: '700' },
41 { label: '800 – Extra-bold', value: '800' },
42 { label: '900 – Black', value: '900' },
43 ];
44
45 var TRANSFORM_OPTIONS = [
46 { label: __('None', 'blockenberg'), value: 'none' },
47 { label: __('Uppercase', 'blockenberg'), value: 'uppercase' },
48 { label: __('Lowercase', 'blockenberg'), value: 'lowercase' },
49 { label: __('Capitalize', 'blockenberg'), value: 'capitalize' },
50 ];
51
52 function buildTextStyle(a) {
53 var style = {
54 textAlign: a.textAlign,
55 WebkitTextStroke: a.strokeWidth + 'px ' + a.strokeColor,
56 color: a.fillColor || 'transparent',
57 display: 'block',
58 transition: 'color ' + a.transitionDuration + 'ms, -webkit-text-stroke-color ' + a.transitionDuration + 'ms, transform ' + a.transitionDuration + 'ms',
59 };
60
61 if (a.shadowBlur > 0) {
62 style.textShadow = '0 0 ' + a.shadowBlur + 'px ' + a.shadowColor;
63 }
64
65 if (a.useGradient) {
66 style.backgroundImage = 'linear-gradient(' + a.gradientAngle + 'deg, ' + a.gradientColor1 + ', ' + a.gradientColor2 + ')';
67 style.WebkitBackgroundClip = 'text';
68 style.backgroundClip = 'text';
69 style.color = 'transparent';
70 style.WebkitTextStroke = a.strokeWidth + 'px transparent';
71 }
72
73 return style;
74 }
75
76 registerBlockType('blockenberg/text-stroke', {
77 title: __('Text Stroke', 'blockenberg'),
78 description: __('Large outlined hollow text with advanced styling.', 'blockenberg'),
79 category: 'bkbg-effects',
80 icon: 'editor-textcolor',
81
82 edit: function (props) {
83 var attributes = props.attributes;
84 var setAttributes = props.setAttributes;
85
86 var blockProps = useBlockProps((function () {
87 var s = {
88 background: attributes.wrapBg || undefined,
89 paddingTop: attributes.paddingTop + 'px',
90 paddingBottom: attributes.paddingBottom + 'px',
91 textAlign: attributes.textAlign,
92 };
93 Object.assign(s, _tvf(attributes.titleTypo, '--bkts-tt-'));
94 return { className: 'bkts-wrap', style: s };
95 })());
96
97 return el(Fragment, null,
98 el(InspectorControls, null,
99 /* ── Text ──────────────────────────────────────────────── */
100 el(PanelBody, { title: __('Text', 'blockenberg'), initialOpen: true },
101 el(TextareaControl, {
102 label: __('Content', 'blockenberg'),
103 value: attributes.text,
104 onChange: function (v) { setAttributes({ text: v }); },
105 rows: 2,
106 }),
107 el(SelectControl, {
108 label: __('HTML tag', 'blockenberg'),
109 value: attributes.tag,
110 options: TAG_OPTIONS,
111 onChange: function (v) { setAttributes({ tag: v }); },
112 }),
113 el(SelectControl, {
114 label: __('Alignment', 'blockenberg'),
115 value: attributes.textAlign,
116 options: [
117 { label: __('Left', 'blockenberg'), value: 'left' },
118 { label: __('Center', 'blockenberg'), value: 'center' },
119 { label: __('Right', 'blockenberg'), value: 'right' },
120 ],
121 onChange: function (v) { setAttributes({ textAlign: v }); },
122 }),
123 el(TextControl, {
124 label: __('Link URL (optional)', 'blockenberg'),
125 value: attributes.linkUrl,
126 type: 'url',
127 onChange: function (v) { setAttributes({ linkUrl: v }); },
128 }),
129 attributes.linkUrl && el(ToggleControl, {
130 label: __('Open in new tab', 'blockenberg'),
131 checked: attributes.linkNewTab,
132 onChange: function (v) { setAttributes({ linkNewTab: v }); },
133 __nextHasNoMarginBottom: true,
134 })
135 ),
136 /* ── Stroke ─────────────────────────────────────────────── */
137 el(PanelBody, { title: __('Stroke', 'blockenberg'), initialOpen: true },
138 el(RangeControl, {
139 label: __('Stroke width (px)', 'blockenberg'),
140 value: attributes.strokeWidth,
141 min: 0, max: 12, step: 0.5,
142 onChange: function (v) { setAttributes({ strokeWidth: v }); },
143 }),
144 el(RangeControl, {
145 label: __('Text shadow blur (px)', 'blockenberg'),
146 value: attributes.shadowBlur,
147 min: 0, max: 60,
148 onChange: function (v) { setAttributes({ shadowBlur: v }); },
149 })
150 ),
151 /* ── Gradient ───────────────────────────────────────────── */
152 el(PanelBody, { title: __('Gradient overlay', 'blockenberg'), initialOpen: false },
153 el(ToggleControl, {
154 label: __('Use gradient', 'blockenberg'),
155 help: __('Applies gradient via background-clip; overrides fill color.', 'blockenberg'),
156 checked: attributes.useGradient,
157 onChange: function (v) { setAttributes({ useGradient: v }); },
158 __nextHasNoMarginBottom: true,
159 }),
160 attributes.useGradient && el(RangeControl, {
161 label: __('Gradient angle (°)', 'blockenberg'),
162 value: attributes.gradientAngle,
163 min: 0, max: 360,
164 onChange: function (v) { setAttributes({ gradientAngle: v }); },
165 })
166 ),
167 /* ── Hover ──────────────────────────────────────────────── */
168 el(PanelBody, { title: __('Hover Effect', 'blockenberg'), initialOpen: false },
169 el(SelectControl, {
170 label: __('Hover effect', 'blockenberg'),
171 value: attributes.hoverEffect,
172 options: HOVER_OPTIONS,
173 onChange: function (v) { setAttributes({ hoverEffect: v }); },
174 }),
175 el(RangeControl, {
176 label: __('Transition duration (ms)', 'blockenberg'),
177 value: attributes.transitionDuration,
178 min: 0, max: 1000, step: 50,
179 onChange: function (v) { setAttributes({ transitionDuration: v }); },
180 })
181 ),
182 /* ── Layout ─────────────────────────────────────────────── */
183 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false },
184 el(RangeControl, {
185 label: __('Padding top (px)', 'blockenberg'),
186 value: attributes.paddingTop,
187 min: 0, max: 160,
188 onChange: function (v) { setAttributes({ paddingTop: v }); },
189 }),
190 el(RangeControl, {
191 label: __('Padding bottom (px)', 'blockenberg'),
192 value: attributes.paddingBottom,
193 min: 0, max: 160,
194 onChange: function (v) { setAttributes({ paddingBottom: v }); },
195 })
196 ),
197 /* ── Colors ─────────────────────────────────────────────── */
198
199 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
200 getTypoControl() && getTypoControl()({
201 label: __('Text', 'blockenberg'),
202 value: attributes.titleTypo || {},
203 onChange: function (v) { setAttributes({ titleTypo: v }); }
204 })
205 ),
206 el(PanelColorSettings, {
207 title: __('Colors', 'blockenberg'),
208 initialOpen: false,
209 colorSettings: [
210 {
211 value: attributes.strokeColor,
212 onChange: function (v) { setAttributes({ strokeColor: v || '#6c3fb5' }); },
213 label: __('Stroke color', 'blockenberg'),
214 },
215 {
216 value: attributes.fillColor === 'transparent' ? '' : attributes.fillColor,
217 onChange: function (v) { setAttributes({ fillColor: v || 'transparent' }); },
218 label: __('Fill color (blank = hollow)', 'blockenberg'),
219 },
220 {
221 value: attributes.hoverFillColor,
222 onChange: function (v) { setAttributes({ hoverFillColor: v || '#6c3fb5' }); },
223 label: __('Hover fill color', 'blockenberg'),
224 },
225 {
226 value: attributes.hoverStrokeColor,
227 onChange: function (v) { setAttributes({ hoverStrokeColor: v || '' }); },
228 label: __('Hover stroke color', 'blockenberg'),
229 },
230 {
231 value: attributes.gradientColor1,
232 onChange: function (v) { setAttributes({ gradientColor1: v || '#6c3fb5' }); },
233 label: __('Gradient color 1', 'blockenberg'),
234 },
235 {
236 value: attributes.gradientColor2,
237 onChange: function (v) { setAttributes({ gradientColor2: v || '#ec4899' }); },
238 label: __('Gradient color 2', 'blockenberg'),
239 },
240 {
241 value: attributes.shadowColor,
242 onChange: function (v) { setAttributes({ shadowColor: v || '#000000' }); },
243 label: __('Shadow color', 'blockenberg'),
244 },
245 {
246 value: attributes.wrapBg,
247 onChange: function (v) { setAttributes({ wrapBg: v || '' }); },
248 label: __('Section background', 'blockenberg'),
249 },
250 ],
251 })
252 ),
253 el('div', blockProps,
254 el(attributes.tag, {
255 className: 'bkts-text',
256 style: buildTextStyle(attributes),
257 contentEditable: true,
258 suppressContentEditableWarning: true,
259 onInput: function (e) { setAttributes({ text: e.currentTarget.textContent }); },
260 }, attributes.text)
261 )
262 );
263 },
264
265 save: function (props) {
266 var a = props.attributes;
267 var textStyle = buildTextStyle(a);
268
269 var blockProps = wp.blockEditor.useBlockProps.save((function () {
270 var s = {
271 background: a.wrapBg || undefined,
272 paddingTop: a.paddingTop + 'px',
273 paddingBottom: a.paddingBottom + 'px',
274 textAlign: a.textAlign,
275 };
276 Object.assign(s, _tvf(a.titleTypo, '--bkts-tt-'));
277 return {
278 className: 'bkts-wrap',
279 style: s,
280 'data-hover': a.hoverEffect,
281 'data-hover-fill': a.hoverFillColor,
282 'data-hover-stroke': a.hoverStrokeColor || a.strokeColor,
283 };
284 })());
285
286 var textEl = el(a.tag, { className: 'bkts-text', style: textStyle }, a.text);
287
288 var inner = a.linkUrl
289 ? el('a', {
290 href: a.linkUrl,
291 target: a.linkNewTab ? '_blank' : undefined,
292 rel: a.linkNewTab ? 'noopener noreferrer' : undefined,
293 style: { textDecoration: 'none', display: 'block' },
294 }, textEl)
295 : textEl;
296
297 return el('div', blockProps, inner);
298 },
299 });
300 }() );
301