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 / color-mixer / index.js

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

223 lines 12.1 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 useState = wp.element.useState;
4 var Fragment = wp.element.Fragment;
5 var registerBlockType = wp.blocks.registerBlockType;
6 var __ = wp.i18n.__;
7 var InspectorControls = wp.blockEditor.InspectorControls;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var useBlockProps = wp.blockEditor.useBlockProps;
10 var PanelBody = wp.components.PanelBody;
11 var RangeControl = wp.components.RangeControl;
12 var SelectControl = wp.components.SelectControl;
13 var TextControl = wp.components.TextControl;
14 var ToggleControl = wp.components.ToggleControl;
15
16 function getTypographyControl() {
17 return (window.bkbgTypographyControl || function () { return null; });
18 }
19
20 var _tv = (function () {
21 var fn = window.bkbgTypoCssVars;
22 return fn ? fn : function () { return {}; };
23 })();
24
25 function mixHex(hexA, hexB, t) {
26 function p(h, s, e) { return parseInt(h.slice(s, e), 16); }
27 var r = Math.round(p(hexA,1,3) + (p(hexB,1,3) - p(hexA,1,3)) * t);
28 var g = Math.round(p(hexA,3,5) + (p(hexB,3,5) - p(hexA,3,5)) * t);
29 var b = Math.round(p(hexA,5,7) + (p(hexB,5,7) - p(hexA,5,7)) * t);
30 function h(x) { return x.toString(16).padStart(2,'0'); }
31 return '#' + h(r) + h(g) + h(b);
32 }
33
34 registerBlockType('blockenberg/color-mixer', {
35 edit: function (props) {
36 var a = props.attributes;
37 var setAttributes = props.setAttributes;
38 var bpStyle = {};
39 Object.assign(bpStyle, _tv(a.typoTitle, '--bkbg-cm-tt'));
40 Object.assign(bpStyle, _tv(a.typoSubtitle, '--bkbg-cm-st'));
41 var blockProps = useBlockProps({ className: 'bkbg-cm-editor-wrap', style: bpStyle });
42
43 var ratio = a.defaultRatio / 100;
44 var mixed = mixHex(a.colorA, a.colorB, ratio);
45
46 var containerStyle = {
47 background: a.sectionBg,
48 borderRadius: '12px',
49 padding: '28px',
50 maxWidth: a.contentMaxWidth + 'px',
51 margin: '0 auto',
52 fontFamily: 'system-ui, sans-serif'
53 };
54
55 var cardStyle = {
56 background: a.cardBg,
57 borderRadius: '10px',
58 padding: '20px',
59 marginBottom: '16px',
60 boxShadow: '0 2px 8px rgba(0,0,0,0.06)'
61 };
62
63 function swatchBox(color, label) {
64 return el('div', { style: { textAlign: 'center' } },
65 el('div', { style: { width: '100%', height: '80px', backgroundColor: color, borderRadius: '8px', marginBottom: '8px', boxShadow: '0 2px 8px rgba(0,0,0,0.12)' } }),
66 el('code', { style: { fontSize: '13px', color: a.labelColor } }, color),
67 el('div', { style: { fontSize: '12px', color: a.subtitleColor, marginTop: '2px' } }, label)
68 );
69 }
70
71 return el(
72 Fragment,
73 null,
74 el(
75 InspectorControls,
76 null,
77 el(
78 PanelBody,
79 { title: __('Content', 'blockenberg'), initialOpen: true },
80 el(TextControl, {
81 label: __('Title', 'blockenberg'),
82 value: a.title,
83 onChange: function (v) { setAttributes({ title: v }); }
84 }),
85 el(TextControl, {
86 label: __('Subtitle', 'blockenberg'),
87 value: a.subtitle,
88 onChange: function (v) { setAttributes({ subtitle: v }); }
89 }),
90 el(ToggleControl, {
91 label: __('Show Title', 'blockenberg'),
92 checked: a.showTitle,
93 onChange: function (v) { setAttributes({ showTitle: v }); },
94 __nextHasNoMarginBottom: true
95 }),
96 el(ToggleControl, {
97 label: __('Show Subtitle', 'blockenberg'),
98 checked: a.showSubtitle,
99 onChange: function (v) { setAttributes({ showSubtitle: v }); },
100 __nextHasNoMarginBottom: true
101 })
102 ),
103 el(
104 PanelBody,
105 { title: __('Colors & Defaults', 'blockenberg'), initialOpen: false },
106 el(TextControl, {
107 label: __('Default Color A', 'blockenberg'),
108 value: a.colorA,
109 onChange: function (v) { setAttributes({ colorA: v }); }
110 }),
111 el(TextControl, {
112 label: __('Default Color B', 'blockenberg'),
113 value: a.colorB,
114 onChange: function (v) { setAttributes({ colorB: v }); }
115 }),
116 el(RangeControl, {
117 label: __('Default Mix Ratio (%)', 'blockenberg'),
118 value: a.defaultRatio,
119 min: 0,
120 max: 100,
121 onChange: function (v) { setAttributes({ defaultRatio: v }); }
122 }),
123 el(ToggleControl, {
124 label: __('Show Color Harmonies', 'blockenberg'),
125 checked: a.showHarmonies,
126 onChange: function (v) { setAttributes({ showHarmonies: v }); },
127 __nextHasNoMarginBottom: true
128 }),
129 el(ToggleControl, {
130 label: __('Show Gradient Strip', 'blockenberg'),
131 checked: a.showGradient,
132 onChange: function (v) { setAttributes({ showGradient: v }); },
133 __nextHasNoMarginBottom: true
134 }),
135 el(ToggleControl, {
136 label: __('Show HEX/RGB/HSL Formats', 'blockenberg'),
137 checked: a.showFormats,
138 onChange: function (v) { setAttributes({ showFormats: v }); },
139 __nextHasNoMarginBottom: true
140 })
141 ),
142 el(
143 PanelBody,
144 { title: __('Typography', 'blockenberg'), initialOpen: false },
145 el(getTypographyControl(), { label: __('Title', 'blockenberg'), value: a.typoTitle, onChange: function (v) { setAttributes({ typoTitle: v }); } }),
146 el(getTypographyControl(), { label: __('Subtitle', 'blockenberg'), value: a.typoSubtitle, onChange: function (v) { setAttributes({ typoSubtitle: v }); } })
147 ),
148 el(
149 PanelBody,
150 { title: __('Appearance', 'blockenberg'), initialOpen: false },
151 el(RangeControl, {
152 label: __('Max Width (px)', 'blockenberg'),
153 value: a.contentMaxWidth,
154 min: 320,
155 max: 1200,
156 onChange: function (v) { setAttributes({ contentMaxWidth: v }); }
157 })
158 ),
159 el(
160 PanelColorSettings,
161 {
162 title: __('UI Colors', 'blockenberg'),
163 initialOpen: false,
164 colorSettings: [
165 { value: a.accentColor, onChange: function (v) { setAttributes({ accentColor: v || '#6366f1' }); }, label: __('Accent Color', 'blockenberg') },
166 { value: a.sectionBg, onChange: function (v) { setAttributes({ sectionBg: v || '#f5f3ff' }); }, label: __('Section Background', 'blockenberg') },
167 { value: a.cardBg, onChange: function (v) { setAttributes({ cardBg: v || '#ffffff' }); }, label: __('Card Background', 'blockenberg') },
168 { value: a.titleColor, onChange: function (v) { setAttributes({ titleColor: v || '#3730a3' }); }, label: __('Title Color', 'blockenberg') },
169 { value: a.subtitleColor, onChange: function (v) { setAttributes({ subtitleColor: v || '#6b7280' }); }, label: __('Subtitle Color', 'blockenberg') },
170 { value: a.labelColor, onChange: function (v) { setAttributes({ labelColor: v || '#374151' }); }, label: __('Label Color', 'blockenberg') }
171 ]
172 }
173 )
174 ),
175 el(
176 'div',
177 blockProps,
178 el(
179 'div',
180 { style: containerStyle },
181 a.showTitle && el('div', { className: 'bkbg-cm-title', style: { color: a.titleColor, marginBottom: '6px' } }, a.title),
182 a.showSubtitle && el('div', { className: 'bkbg-cm-subtitle', style: { color: a.subtitleColor, marginBottom: '20px' } }, a.subtitle),
183 // Color pickers row
184 el('div', { style: Object.assign({}, cardStyle, { display: 'grid', gridTemplateColumns: '1fr auto 1fr', gap: '16px', alignItems: 'center' }) },
185 swatchBox(a.colorA, 'Color A'),
186 el('div', { style: { textAlign: 'center', color: a.labelColor, fontWeight: '700', fontSize: '18px' } }, '+'),
187 swatchBox(a.colorB, 'Color B')
188 ),
189 // Ratio + Mixed result
190 el('div', { style: cardStyle },
191 el('div', { style: { marginBottom: '14px' } },
192 el('div', { style: { display: 'flex', justifyContent: 'space-between', fontSize: '13px', color: a.labelColor, marginBottom: '6px' } },
193 el('span', null, 'A (' + (100 - a.defaultRatio) + '%)'),
194 el('span', { style: { fontWeight: '600' } }, 'Mix Ratio'),
195 el('span', null, 'B (' + a.defaultRatio + '%)')
196 ),
197 el('input', { type: 'range', min: 0, max: 100, defaultValue: a.defaultRatio, style: { width: '100%', accentColor: a.accentColor } })
198 ),
199 el('div', { style: { height: '60px', background: mixed, borderRadius: '8px', marginBottom: '12px', boxShadow: '0 2px 8px rgba(0,0,0,0.10)' } }),
200 el('div', { style: { textAlign: 'center', fontFamily: 'monospace', fontSize: '18px', fontWeight: '700', color: a.labelColor } }, mixed)
201 ),
202 // Gradient strip
203 a.showGradient && el('div', { style: Object.assign({}, cardStyle, { padding: '16px' }) },
204 el('div', { style: { fontSize: '13px', fontWeight: '600', color: a.labelColor, marginBottom: '10px' } }, 'Gradient'),
205 el('div', { style: { height: '32px', borderRadius: '8px', background: 'linear-gradient(to right, ' + a.colorA + ', ' + a.colorB + ')' } })
206 )
207 )
208 )
209 );
210 },
211 save: function (props) {
212 var a = props.attributes;
213 var blockProps = wp.blockEditor.useBlockProps.save();
214 return el('div', blockProps,
215 el('div', {
216 className: 'bkbg-cm-app',
217 'data-opts': JSON.stringify(a)
218 })
219 );
220 }
221 });
222 }() );
223