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 / meme-generator / index.js

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

167 lines 10.4 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 RichText = wp.blockEditor.RichText;
10 var PanelBody = wp.components.PanelBody;
11 var RangeControl = wp.components.RangeControl;
12 var ToggleControl = wp.components.ToggleControl;
13 var SelectControl = wp.components.SelectControl;
14 var TextControl = wp.components.TextControl;
15
16 var _tc, _tv;
17 function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
18 function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
19
20 var FONT_OPTIONS = [
21 { label: 'Impact (Classic Meme)', value: 'Impact' },
22 { label: 'Arial Black', value: 'Arial Black' },
23 { label: 'Comic Sans MS', value: 'Comic Sans MS' },
24 { label: 'Georgia Bold', value: 'Georgia' },
25 { label: 'Courier New', value: 'Courier New' }
26 ];
27
28 function EditorPreview(props) {
29 var a = props.attributes;
30 var setAttributes = props.setAttributes;
31 var blockProps = (function(p){
32 var v = getTypoCssVars() || function () { return {}; };
33 p.style = Object.assign(p.style||{},
34 v(a.titleTypo,'--bkbg-mme-tt-'),
35 v(a.subtitleTypo,'--bkbg-mme-st-')
36 ); return p;
37 })(useBlockProps({ style: { background: a.sectionBg || '#f8fafc', padding: '24px 20px' } }));
38
39 // Mock meme preview (static SVG in editor)
40 var previewStyle = {
41 position: 'relative', width: '100%', maxWidth: a.canvasWidth,
42 height: Math.min(a.canvasHeight, 380),
43 background: a.canvasBg || '#cccccc',
44 borderRadius: 8, overflow: 'hidden', margin: '0 auto',
45 display: 'flex', alignItems: 'center', justifyContent: 'center',
46 border: '2px dashed ' + a.accentColor + '55'
47 };
48
49 var textStyle = function (bottom) { return ({
50 position: 'absolute', left: 0, right: 0,
51 top: bottom ? 'auto' : 12, bottom: bottom ? 12 : 'auto',
52 textAlign: 'center', fontFamily: a.memeFont,
53 fontSize: Math.min(a.memeFontSize, 52) + 'px',
54 color: a.memeTextColor, fontWeight: 700,
55 textShadow: '2px 2px 0 ' + a.memeStrokeColor + ', -2px -2px 0 ' + a.memeStrokeColor + ', 2px -2px 0 ' + a.memeStrokeColor + ', -2px 2px 0 ' + a.memeStrokeColor,
56 padding: '0 12px', lineHeight: 1.2,
57 pointerEvents: 'none', letterSpacing: '0.04em'
58 }); };
59
60 return el(Fragment, null,
61 el(InspectorControls, null,
62 el(PanelBody, { title: __('Block Content', 'blockenberg'), initialOpen: true },
63 ),
64 el(PanelBody, { title: __('Canvas Settings', 'blockenberg'), initialOpen: false },
65 el(TextControl, {
66 label: __('Default Image URL', 'blockenberg'), value: a.defaultImageUrl,
67 help: __('Visitors can change this — leave blank to use a plain background.', 'blockenberg'),
68 onChange: function (v) { setAttributes({ defaultImageUrl: v }); }
69 }),
70 el(TextControl, {
71 label: __('Default Top Text', 'blockenberg'), value: a.defaultTopText,
72 onChange: function (v) { setAttributes({ defaultTopText: v }); }
73 }),
74 el(TextControl, {
75 label: __('Default Bottom Text', 'blockenberg'), value: a.defaultBottomText,
76 onChange: function (v) { setAttributes({ defaultBottomText: v }); }
77 }),
78 el(RangeControl, { label: __('Canvas Width (px)', 'blockenberg'), value: a.canvasWidth, min: 280, max: 900,
79 onChange: function (v) { setAttributes({ canvasWidth: v }); } }),
80 el(RangeControl, { label: __('Canvas Height (px)', 'blockenberg'), value: a.canvasHeight, min: 200, max: 700,
81 onChange: function (v) { setAttributes({ canvasHeight: v }); } })
82 ),
83 el(PanelBody, { title: __('Meme Text Style', 'blockenberg'), initialOpen: false },
84 el(SelectControl, { label: __('Font', 'blockenberg'), value: a.memeFont, options: FONT_OPTIONS,
85 onChange: function (v) { setAttributes({ memeFont: v }); } }),
86 el(RangeControl, { label: __('Stroke Width (px)', 'blockenberg'), value: a.memeStrokeWidth, min: 0, max: 12,
87 onChange: function (v) { setAttributes({ memeStrokeWidth: v }); } }),
88 el(ToggleControl, { __nextHasNoMarginBottom: true, label: __('Show Download Button', 'blockenberg'), checked: a.showDownload,
89 onChange: function (v) { setAttributes({ showDownload: v }); } })
90 ),
91
92 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
93 getTypoControl() && el(getTypoControl(), { label: 'Title', value: a.titleTypo || {}, onChange: function(v){ setAttributes({ titleTypo: v }); } }),
94 getTypoControl() && el(getTypoControl(), { label: 'Subtitle', value: a.subtitleTypo || {}, onChange: function(v){ setAttributes({ subtitleTypo: v }); } }),
95 el(RangeControl, { label: __('Meme Font Size (px)', 'blockenberg'), value: a.memeFontSize, min: 20, max: 120,
96 onChange: function (v) { setAttributes({ memeFontSize: v }); } })
97 ),
98 el(PanelColorSettings, {
99 title: __('Colors', 'blockenberg'), initialOpen: false,
100 colorSettings: [
101 { label: __('Canvas Background', 'blockenberg'), value: a.canvasBg, onChange: function (v) { setAttributes({ canvasBg: v || '#cccccc' }); } },
102 { label: __('Meme Text Color', 'blockenberg'), value: a.memeTextColor, onChange: function (v) { setAttributes({ memeTextColor: v || '#ffffff' }); } },
103 { label: __('Meme Stroke Color', 'blockenberg'), value: a.memeStrokeColor, onChange: function (v) { setAttributes({ memeStrokeColor: v || '#000000' }); } },
104 { label: __('Section Background', 'blockenberg'), value: a.sectionBg, onChange: function (v) { setAttributes({ sectionBg: v || '#f8fafc' }); } },
105 { label: __('Title Color', 'blockenberg'), value: a.titleColor, onChange: function (v) { setAttributes({ titleColor: v || '#1e1b4b' }); } },
106 { label: __('Accent Color', 'blockenberg'), value: a.accentColor, onChange: function (v) { setAttributes({ accentColor: v || '#6366f1' }); } }
107 ]
108 })
109 ),
110 el('div', blockProps,
111 el(RichText, { tagName: 'h3', className: 'bkbg-mme-title', value: a.title,
112 onChange: function (v) { setAttributes({ title: v }); },
113 placeholder: __('Meme Generator', 'blockenberg'),
114 style: { color: a.titleColor, textAlign: 'center' } }),
115 el(RichText, { tagName: 'p', className: 'bkbg-mme-subtitle', value: a.subtitle,
116 onChange: function (v) { setAttributes({ subtitle: v }); },
117 placeholder: __('Add your text and download!', 'blockenberg'),
118 style: { color: a.titleColor, textAlign: 'center' } }),
119 // Canvas mock preview
120 el('div', { style: previewStyle },
121 el('div', { style: { color: a.titleColor, opacity: 0.35, textAlign: 'center', fontSize: 13 } },
122 el('div', { style: { fontSize: 32, marginBottom: 4 } }, '🖼️'),
123 a.defaultImageUrl ? 'Image: ' + a.defaultImageUrl.substring(0, 40) + '' : 'No image set — plain background'
124 ),
125 el('div', { style: textStyle(false) }, a.defaultTopText || 'TOP TEXT'),
126 el('div', { style: textStyle(true) }, a.defaultBottomText || 'BOTTOM TEXT')
127 ),
128 // UI controls hint
129 el('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap', justifyContent: 'center', marginTop: 12 } },
130 el('div', { style: { background: a.accentColor, color: '#fff', borderRadius: 6, padding: '7px 18px', fontSize: 13, fontWeight: 600, opacity: 0.5 } }, '📋 Paste Image URL'),
131 el('div', { style: { background: a.accentColor, color: '#fff', borderRadius: 6, padding: '7px 18px', fontSize: 13, fontWeight: 600, opacity: 0.5 } }, '📝 Edit Text'),
132 a.showDownload && el('div', { style: { background: '#22c55e', color: '#fff', borderRadius: 6, padding: '7px 18px', fontSize: 13, fontWeight: 600, opacity: 0.5 } }, '⬇️ Download PNG')
133 )
134 )
135 );
136 }
137
138 registerBlockType('blockenberg/meme-generator', {
139 edit: EditorPreview,
140 deprecated: [{
141 save: function (props) {
142 var a = props.attributes;
143 return el('div', useBlockProps.save(),
144 el('div', { className: 'bkbg-mme-app', 'data-opts': JSON.stringify(a) },
145 el(RichText.Content, { tagName: 'h3', className: 'bkbg-mme-title', value: a.title }),
146 el(RichText.Content, { tagName: 'p', className: 'bkbg-mme-subtitle', value: a.subtitle })
147 )
148 );
149 }
150 }],
151 save: function (props) {
152 var a = props.attributes;
153 var v = (typeof window.bkbgTypoCssVars === 'function') ? window.bkbgTypoCssVars : function () { return {}; };
154 var s = Object.assign({},
155 v(a.titleTypo,'--bkbg-mme-tt-'),
156 v(a.subtitleTypo,'--bkbg-mme-st-')
157 );
158 return el('div', (function(p){p.style=Object.assign(p.style||{},s);return p;})(useBlockProps.save()),
159 el('div', { className: 'bkbg-mme-app', 'data-opts': JSON.stringify(a) },
160 el(RichText.Content, { tagName: 'h3', className: 'bkbg-mme-title', value: a.title }),
161 el(RichText.Content, { tagName: 'p', className: 'bkbg-mme-subtitle', value: a.subtitle })
162 )
163 );
164 }
165 });
166 }() );
167