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 / liquid-glass-cards / index.js

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

278 lines 17.0 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 registerBlockType = wp.blocks.registerBlockType;
4 var useBlockProps = wp.blockEditor.useBlockProps;
5 var InspectorControls = wp.blockEditor.InspectorControls;
6 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
7 var PanelBody = wp.components.PanelBody;
8 var RangeControl = wp.components.RangeControl;
9 var ToggleControl = wp.components.ToggleControl;
10 var TextControl = wp.components.TextControl;
11 var SelectControl = wp.components.SelectControl;
12 var Button = wp.components.Button;
13 var GradientPicker = wp.components.__experimentalGradientPicker;
14
15 var _tc, _tv;
16 function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
17 function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
18 var IP = function () { return window.bkbgIconPicker; };
19
20 registerBlockType('blockenberg/liquid-glass-cards', {
21 edit: function (props) {
22 var a = props.attributes;
23 var set = props.setAttributes;
24 var blockProps = useBlockProps((function () {
25 var _tvFn = getTypoCssVars();
26 var s = {};
27 if (_tvFn) {
28 Object.assign(s, _tvFn(a.titleTypo, '--bkbg-lgc-tt-'));
29 Object.assign(s, _tvFn(a.descTypo, '--bkbg-lgc-d-'));
30 }
31 return { style: s };
32 })());
33
34 function updateCard(idx, field, val) {
35 var nc = a.cards.map(function (c, i) {
36 return i === idx ? Object.assign({}, c, { [field]: val }) : c;
37 });
38 set({ cards: nc });
39 }
40 function addCard() {
41 set({ cards: a.cards.concat([{ icon: '✨', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '', title: 'New Card', description: 'Card description goes here.', linkUrl: '', linkText: 'Learn More' }]) });
42 }
43 function removeCard(idx) {
44 set({ cards: a.cards.filter(function (_, i) { return i !== idx; }) });
45 }
46
47 var cols = a.columns || 3;
48 var blur = a.blurAmount || 20;
49 var gOp = (a.glassOpacity || 18) / 100;
50 var bOp = (a.borderOpacity || 30) / 100;
51 var gc = a.glassColor || '#ffffff';
52 // Parse hex to RGB for rgba
53 var glassRgb = hexToRgb(gc) || '255,255,255';
54 var borderRgb = hexToRgb(a.borderColor || 'rgba(255,255,255,0.3)') || '255,255,255';
55
56 function hexToRgb(c) {
57 if (!c) return null;
58 var m = c.match(/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i);
59 return m ? parseInt(m[1], 16) + ',' + parseInt(m[2], 16) + ',' + parseInt(m[3], 16) : null;
60 }
61
62 var wrapStyle = {
63 background: a.bgGradient || 'linear-gradient(135deg,#667eea 0%,#764ba2 100%)',
64 padding: '40px 32px',
65 borderRadius: 16
66 };
67
68 var gridStyle = {
69 display: 'grid',
70 gridTemplateColumns: 'repeat(' + cols + ', 1fr)',
71 gap: '20px'
72 };
73
74 var cardStyle = {
75 background: 'rgba(' + glassRgb + ',' + gOp + ')',
76 backdropFilter: 'blur(' + blur + 'px)',
77 WebkitBackdropFilter: 'blur(' + blur + 'px)',
78 border: '1px solid rgba(' + borderRgb + ',' + bOp + ')',
79 borderRadius: (a.cardRadius || 24) + 'px',
80 padding: (a.cardPadding || 32) + 'px',
81 boxShadow: '0 8px 32px ' + (a.shadowColor || 'rgba(0,0,0,0.2)'),
82 display: 'flex',
83 flexDirection: 'column',
84 gap: 12
85 };
86
87 return el('div', blockProps,
88 el(InspectorControls, {},
89 el(PanelBody, { title: 'Cards', initialOpen: true },
90 (a.cards || []).map(function (card, i) {
91 return el('div', { key: i, style: { marginBottom: 12, padding: 10,
92 background: '#f8fafc', borderRadius: 6, border: '1px solid #e5e7eb' } },
93 el('strong', { style: { display: 'block', marginBottom: 6, fontSize: 12 } }, 'Card ' + (i + 1)),
94 el(IP().IconPickerControl, {
95 iconType: card.iconType || 'custom-char',
96 customChar: card.icon || '',
97 dashicon: card.iconDashicon || '',
98 imageUrl: card.iconImageUrl || '',
99 onChangeType: function (v) { updateCard(i, 'iconType', v); },
100 onChangeChar: function (v) { updateCard(i, 'icon', v); },
101 onChangeDashicon: function (v) { updateCard(i, 'iconDashicon', v); },
102 onChangeImageUrl: function (v) { updateCard(i, 'iconImageUrl', v); },
103 label: 'Icon'
104 }),
105 el(TextControl, { label: 'Title', value: card.title || '',
106 onChange: function (v) { updateCard(i, 'title', v); }, __nextHasNoMarginBottom: true }),
107 el(TextControl, { label: 'Description', value: card.description || '',
108 onChange: function (v) { updateCard(i, 'description', v); }, __nextHasNoMarginBottom: true }),
109 el(TextControl, { label: 'Link URL', value: card.linkUrl || '',
110 onChange: function (v) { updateCard(i, 'linkUrl', v); }, __nextHasNoMarginBottom: true }),
111 el(TextControl, { label: 'Link text', value: card.linkText || '',
112 onChange: function (v) { updateCard(i, 'linkText', v); }, __nextHasNoMarginBottom: true }),
113 el(Button, { isDestructive: true, isSmall: true,
114 onClick: function () { removeCard(i); }, style: { marginTop: 4 } }, '✕ Remove')
115 );
116 }),
117 el(Button, { isPrimary: true, isSmall: true, onClick: addCard, style: { marginTop: 4 } }, '+ Add Card')
118 ),
119 el(PanelBody, { title: 'Layout', initialOpen: false },
120 el(SelectControl, { label: 'Columns', value: String(a.columns || 3),
121 options: [
122 { label: '1', value: '1' }, { label: '2', value: '2' },
123 { label: '3', value: '3' }, { label: '4', value: '4' }
124 ],
125 onChange: function (v) { set({ columns: Number(v) }); }, __nextHasNoMarginBottom: true }),
126 el(ToggleControl, { label: 'Show link button', checked: a.showLink !== false,
127 onChange: function (v) { set({ showLink: v }); }, __nextHasNoMarginBottom: true }),
128 el(RangeControl, { label: 'Card radius', value: a.cardRadius || 24,
129 onChange: function (v) { set({ cardRadius: v }); }, min: 0, max: 60, __nextHasNoMarginBottom: true }),
130 el(RangeControl, { label: 'Card padding', value: a.cardPadding || 32,
131 onChange: function (v) { set({ cardPadding: v }); }, min: 12, max: 72, __nextHasNoMarginBottom: true }),
132 el(RangeControl, { label: 'Icon size', value: a.iconSize || 44,
133 onChange: function (v) { set({ iconSize: v }); }, min: 24, max: 80, __nextHasNoMarginBottom: true }),
134 ),
135 el(PanelBody, { title: 'Glass Effect', initialOpen: false },
136 el(RangeControl, { label: 'Blur amount (px)', value: a.blurAmount || 20,
137 onChange: function (v) { set({ blurAmount: v }); }, min: 0, max: 60, __nextHasNoMarginBottom: true }),
138 el(RangeControl, { label: 'Glass opacity (%)', value: a.glassOpacity || 18,
139 onChange: function (v) { set({ glassOpacity: v }); }, min: 0, max: 80, __nextHasNoMarginBottom: true }),
140 el(RangeControl, { label: 'Border opacity (%)', value: a.borderOpacity || 30,
141 onChange: function (v) { set({ borderOpacity: v }); }, min: 0, max: 100, __nextHasNoMarginBottom: true }),
142 el(RangeControl, { label: 'Parallax strength', value: a.parallaxStrength || 8,
143 onChange: function (v) { set({ parallaxStrength: v }); }, min: 0, max: 30, __nextHasNoMarginBottom: true })
144 ),
145
146 el( PanelBody, { title: 'Typography', initialOpen: false },
147 getTypoControl() && el(getTypoControl(), { label: 'Title', value: a.titleTypo || {}, onChange: function (v) { set({ titleTypo: v }); } }),
148 getTypoControl() && el(getTypoControl(), { label: 'Description', value: a.descTypo || {}, onChange: function (v) { set({ descTypo: v }); } })
149 ),
150 el(PanelColorSettings, {
151 title: 'Colors', initialOpen: false,
152 colorSettings: [
153 { label: 'Glass tint', value: a.glassColor, onChange: function (v) { set({ glassColor: v || '#ffffff' }); } },
154 { label: 'Border color', value: a.borderColor,onChange: function (v) { set({ borderColor: v || 'rgba(255,255,255,0.3)' }); } },
155 { label: 'Title', value: a.titleColor, onChange: function (v) { set({ titleColor: v || '#ffffff' }); } },
156 { label: 'Description', value: a.descColor, onChange: function (v) { set({ descColor: v || 'rgba(255,255,255,0.8)' }); } },
157 { label: 'Icon bubble', value: a.iconBg, onChange: function (v) { set({ iconBg: v || 'rgba(255,255,255,0.2)' }); } },
158 { label: 'Link text', value: a.linkColor, onChange: function (v) { set({ linkColor: v || '#ffffff' }); } },
159 { label: 'Card shadow', value: a.shadowColor,onChange: function (v) { set({ shadowColor: v || 'rgba(0,0,0,0.2)' }); } }
160 ],
161 disableCustomGradients: true
162 }),
163 el(PanelBody, { title: 'Background Gradient', initialOpen: false },
164 el(GradientPicker, {
165 value: a.bgGradient || '',
166 onChange: function (v) { set({ bgGradient: v }); }
167 })
168 )
169 ),
170
171 el('div', { style: wrapStyle },
172 el('div', { style: gridStyle },
173 (a.cards || []).map(function (card, i) {
174 return el('div', { key: i, style: cardStyle },
175 el('div', {
176 style: {
177 width: (a.iconSize || 44) + 'px',
178 height: (a.iconSize || 44) + 'px',
179 borderRadius: '50%',
180 background: a.iconBg || 'rgba(255,255,255,0.2)',
181 display: 'flex', alignItems: 'center',
182 justifyContent: 'center',
183 fontSize: Math.round((a.iconSize || 44) * 0.55) + 'px',
184 flexShrink: 0
185 }
186 }, (function () {
187 var _ct = card.iconType || 'custom-char';
188 if (_ct !== 'custom-char' && IP()) {
189 var _n = IP().buildEditorIcon(_ct, card.icon, card.iconDashicon, card.iconImageUrl, card.iconDashiconColor);
190 if (_n) return _n;
191 }
192 return card.icon || '✨';
193 })()),
194 el('h3', { className: 'bkbg-lgc-title', style: { margin: 0, color: a.titleColor || '#ffffff', lineHeight: 1.3 } },
195 card.title || ''),
196 el('p', { className: 'bkbg-lgc-desc', style: { margin: 0, color: a.descColor || 'rgba(255,255,255,0.8)', lineHeight: 1.6 } },
197 card.description || ''),
198 a.showLink !== false && el('a', {
199 href: card.linkUrl || '#',
200 style: { color: a.linkColor || '#ffffff', fontSize: 14, fontWeight: 600,
201 textDecoration: 'none', marginTop: 'auto', display: 'inline-flex',
202 alignItems: 'center', gap: 4 }
203 }, (card.linkText || 'Learn More') + ' →')
204 );
205 })
206 )
207 )
208 );
209 },
210
211 save: function (props) {
212 var a = props.attributes;
213 var blockProps = useBlockProps.save();
214 var opts = {
215 blurAmount: a.blurAmount || 20,
216 glassOpacity: a.glassOpacity || 18,
217 borderOpacity: a.borderOpacity || 30,
218 parallaxStrength: a.parallaxStrength || 8,
219 glassColor: a.glassColor || '#ffffff',
220 borderColor: a.borderColor || 'rgba(255,255,255,0.3)',
221 shadowColor: a.shadowColor || 'rgba(0,0,0,0.2)',
222 iconBg: a.iconBg || 'rgba(255,255,255,0.2)',
223 titleColor: a.titleColor || '#ffffff',
224 descColor: a.descColor || 'rgba(255,255,255,0.8)',
225 linkColor: a.linkColor || '#ffffff'
226 };
227 return el('div', blockProps,
228 el('div', {
229 className: 'bkbg-lgc-app',
230 'data-opts': JSON.stringify(opts),
231 style: (function () {
232 var _tvFn = getTypoCssVars();
233 var s = { background: a.bgGradient || 'linear-gradient(135deg,#667eea 0%,#764ba2 100%)' };
234 if (_tvFn) {
235 Object.assign(s, _tvFn(a.titleTypo, '--bkbg-lgc-tt-'));
236 Object.assign(s, _tvFn(a.descTypo, '--bkbg-lgc-d-'));
237 }
238 return s;
239 })()
240 },
241 el('div', {
242 className: 'bkbg-lgc-grid',
243 style: { gridTemplateColumns: 'repeat(' + (a.columns || 3) + ',1fr)' }
244 },
245 (a.cards || []).map(function (card, i) {
246 return el('div', { key: i, className: 'bkbg-lgc-card',
247 style: {
248 borderRadius: (a.cardRadius || 24) + 'px',
249 padding: (a.cardPadding || 32) + 'px'
250 }
251 },
252 el('div', { className: 'bkbg-lgc-icon',
253 style: { width: (a.iconSize || 44) + 'px', height: (a.iconSize || 44) + 'px',
254 fontSize: Math.round((a.iconSize || 44) * 0.55) + 'px' } },
255 (function () {
256 var _ct = card.iconType || 'custom-char';
257 if (_ct !== 'custom-char' && IP()) {
258 var _n = IP().buildSaveIcon(_ct, card.icon, card.iconDashicon, card.iconImageUrl, card.iconDashiconColor);
259 if (_n) return _n;
260 }
261 return card.icon || '';
262 })()),
263 el('h3', { className: 'bkbg-lgc-title' }, card.title || ''),
264 el('p', { className: 'bkbg-lgc-desc' }, card.description || ''),
265 a.showLink !== false && el('a', {
266 className: 'bkbg-lgc-link',
267 href: card.linkUrl || '#',
268 rel: 'noopener'
269 }, (card.linkText || 'Learn More') + ' →')
270 );
271 })
272 )
273 )
274 );
275 }
276 });
277 }() );
278