| 1 |
( function () { |
| 2 |
var el = wp.element.createElement; |
| 3 |
var __ = wp.i18n.__; |
| 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 TextControl = wp.components.TextControl; |
| 9 |
var ToggleControl = wp.components.ToggleControl; |
| 10 |
var SelectControl = wp.components.SelectControl; |
| 11 |
var RangeControl = wp.components.RangeControl; |
| 12 |
|
| 13 |
var STYLES = [ |
| 14 |
{ label: 'Sparkle ✨', value: 'sparkle' }, |
| 15 |
{ label: 'Dots', value: 'dots' }, |
| 16 |
{ label: 'Comet ☄️', value: 'comet' }, |
| 17 |
{ label: 'Stars ⭐', value: 'stars' }, |
| 18 |
{ label: 'Fire 🔥', value: 'fire' }, |
| 19 |
{ label: 'Snow ❄️', value: 'snow' }, |
| 20 |
{ label: 'Ribbon', value: 'ribbon' } |
| 21 |
]; |
| 22 |
|
| 23 |
var COLOR_MODES = [ |
| 24 |
{ label: 'Gradient (2 colors)', value: 'gradient' }, |
| 25 |
{ label: 'Solid Primary', value: 'solid' }, |
| 26 |
{ label: 'Rainbow', value: 'rainbow' } |
| 27 |
]; |
| 28 |
|
| 29 |
var SCOPES = [ |
| 30 |
{ label: 'Whole Page', value: 'page' }, |
| 31 |
{ label: 'Section Only', value: 'section' } |
| 32 |
]; |
| 33 |
|
| 34 |
var BLEND_MODES = [ |
| 35 |
'normal','screen','overlay','lighten','color-dodge','add' |
| 36 |
].map(function (v) { return { label: v, value: v }; }); |
| 37 |
|
| 38 |
function EditorPreview(props) { |
| 39 |
var attr = props.attr; |
| 40 |
return el('div', { |
| 41 |
style: { |
| 42 |
width: '100%', height: attr.sectionHeight + 'px', |
| 43 |
backgroundColor: attr.sectionBg, |
| 44 |
borderRadius: attr.sectionRadius + 'px', |
| 45 |
display: 'flex', alignItems: 'center', justifyContent: 'center', |
| 46 |
position: 'relative', overflow: 'hidden', |
| 47 |
cursor: 'none' |
| 48 |
} |
| 49 |
}, |
| 50 |
el('p', { |
| 51 |
style: { |
| 52 |
color: '#fff', fontSize: '16px', fontWeight: 600, |
| 53 |
opacity: 0.8, letterSpacing: '0.04em', textAlign: 'center', |
| 54 |
padding: '0 20px', margin: 0 |
| 55 |
} |
| 56 |
}, attr.previewText || 'Move your cursor here ✨'), |
| 57 |
el('div', { |
| 58 |
style: { |
| 59 |
position: 'absolute', bottom: '12px', right: '16px', |
| 60 |
fontSize: '11px', color: 'rgba(255,255,255,0.4)', letterSpacing: '0.05em' |
| 61 |
} |
| 62 |
}, 'Trail: ' + (STYLES.find(function (s) { return s.value === attr.trailStyle; }) || STYLES[0]).label + |
| 63 |
' · Scope: ' + attr.scope), |
| 64 |
// Sample particle dots for visual hint |
| 65 |
[0, 1, 2, 3, 4].map(function (i) { |
| 66 |
return el('div', { |
| 67 |
key: i, |
| 68 |
style: { |
| 69 |
position: 'absolute', |
| 70 |
left: (25 + i * 12) + '%', |
| 71 |
top: (35 + Math.sin(i * 1.2) * 20) + '%', |
| 72 |
width: attr.particleSize + 'px', |
| 73 |
height: attr.particleSize + 'px', |
| 74 |
borderRadius: '50%', |
| 75 |
background: attr.colorMode === 'rainbow' |
| 76 |
? 'hsl(' + (i * 60) + ',90%,65%)' |
| 77 |
: (i % 2 === 0 ? attr.color1 : attr.color2), |
| 78 |
opacity: 1 - i * 0.18, |
| 79 |
boxShadow: attr.glowEffect ? '0 0 ' + attr.glowSize + 'px ' + attr.color1 : undefined, |
| 80 |
transform: 'scale(' + (1 - i * 0.15) + ')', |
| 81 |
pointerEvents: 'none' |
| 82 |
} |
| 83 |
}); |
| 84 |
}) |
| 85 |
); |
| 86 |
} |
| 87 |
|
| 88 |
wp.blocks.registerBlockType('blockenberg/mouse-trail', { |
| 89 |
title: 'Mouse Trail', |
| 90 |
icon: 'admin-customizer', |
| 91 |
category: 'bkbg-effects', |
| 92 |
edit: function (props) { |
| 93 |
var attr = props.attributes; |
| 94 |
var setAttr = props.setAttributes; |
| 95 |
var blockProps = useBlockProps({ style: { fontFamily: 'inherit' } }); |
| 96 |
|
| 97 |
return el('div', blockProps, |
| 98 |
el(InspectorControls, {}, |
| 99 |
el(PanelBody, { title: __('Trail Style', 'blockenberg'), initialOpen: true }, |
| 100 |
el(SelectControl, { __nextHasNoMarginBottom: true, label: __('Style', 'blockenberg'), value: attr.trailStyle, options: STYLES, onChange: function (v) { setAttr({ trailStyle: v }); } }), |
| 101 |
el(SelectControl, { __nextHasNoMarginBottom: true, label: __('Color Mode', 'blockenberg'), value: attr.colorMode, options: COLOR_MODES, onChange: function (v) { setAttr({ colorMode: v }); } }), |
| 102 |
el(SelectControl, { __nextHasNoMarginBottom: true, label: __('Blend Mode', 'blockenberg'), value: attr.mixBlend, options: BLEND_MODES, onChange: function (v) { setAttr({ mixBlend: v }); } }) |
| 103 |
), |
| 104 |
el(PanelBody, { title: __('Particles', 'blockenberg'), initialOpen: false }, |
| 105 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: __('Max Particles', 'blockenberg'), value: attr.particleCount, min: 5, max: 100, onChange: function (v) { setAttr({ particleCount: v }); } }), |
| 106 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: __('Particle Size (px)', 'blockenberg'), value: attr.particleSize, min: 2, max: 30, onChange: function (v) { setAttr({ particleSize: v }); } }), |
| 107 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: __('Spread Radius (px)', 'blockenberg'), value: attr.spreadRadius, min: 0, max: 80, onChange: function (v) { setAttr({ spreadRadius: v }); } }), |
| 108 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: __('Trail Fade Speed', 'blockenberg'), help: __('Higher = quicker fade', 'blockenberg'), value: attr.trailFade, min: 10, max: 100, onChange: function (v) { setAttr({ trailFade: v }); } }), |
| 109 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: __('Gravity', 'blockenberg'), value: Math.round(attr.gravity * 100), min: 0, max: 100, onChange: function (v) { setAttr({ gravity: v / 100 }); } }) |
| 110 |
), |
| 111 |
el(PanelBody, { title: __('Glow & Effects', 'blockenberg'), initialOpen: false }, |
| 112 |
el(ToggleControl, { __nextHasNoMarginBottom: true, label: __('Glow Effect', 'blockenberg'), checked: attr.glowEffect, onChange: function (v) { setAttr({ glowEffect: v }); } }), |
| 113 |
attr.glowEffect && el(RangeControl, { __nextHasNoMarginBottom: true, label: __('Glow Size (px)', 'blockenberg'), value: attr.glowSize, min: 2, max: 40, onChange: function (v) { setAttr({ glowSize: v }); } }), |
| 114 |
el(ToggleControl, { __nextHasNoMarginBottom: true, label: __('Burst on Click', 'blockenberg'), checked: attr.burstOnClick, onChange: function (v) { setAttr({ burstOnClick: v }); } }), |
| 115 |
attr.burstOnClick && el(RangeControl, { __nextHasNoMarginBottom: true, label: __('Burst Particle Count', 'blockenberg'), value: attr.burstCount, min: 5, max: 60, onChange: function (v) { setAttr({ burstCount: v }); } }) |
| 116 |
), |
| 117 |
el(PanelBody, { title: __('Scope & Behavior', 'blockenberg'), initialOpen: false }, |
| 118 |
el(SelectControl, { __nextHasNoMarginBottom: true, label: __('Effect Scope', 'blockenberg'), help: __("'Page' attaches to the whole page; 'Section' only applies inside this block", 'blockenberg'), value: attr.scope, options: SCOPES, onChange: function (v) { setAttr({ scope: v }); } }), |
| 119 |
el(ToggleControl, { __nextHasNoMarginBottom: true, label: __('Show on Mobile Devices', 'blockenberg'), checked: attr.showOnMobile, onChange: function (v) { setAttr({ showOnMobile: v }); } }) |
| 120 |
), |
| 121 |
el(PanelBody, { title: __('Section (when scoped)', 'blockenberg'), initialOpen: false }, |
| 122 |
el(TextControl, { __nextHasNoMarginBottom: true, label: __('Section Label/Text', 'blockenberg'), value: attr.previewText, onChange: function (v) { setAttr({ previewText: v }); } }), |
| 123 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: __('Section Height (px)', 'blockenberg'), value: attr.sectionHeight, min: 80, max: 600, step: 10, onChange: function (v) { setAttr({ sectionHeight: v }); } }), |
| 124 |
el(RangeControl, { __nextHasNoMarginBottom: true, label: __('Section Border Radius', 'blockenberg'), value: attr.sectionRadius, min: 0, max: 40, onChange: function (v) { setAttr({ sectionRadius: v }); } }) |
| 125 |
), |
| 126 |
el(PanelColorSettings, { |
| 127 |
title: __('Colors', 'blockenberg'), |
| 128 |
initialOpen: false, |
| 129 |
colorSettings: [ |
| 130 |
{ label: __('Primary Color', 'blockenberg'), value: attr.color1, onChange: function (v) { setAttr({ color1: v || '' }); } }, |
| 131 |
{ label: __('Secondary Color', 'blockenberg'), value: attr.color2, onChange: function (v) { setAttr({ color2: v || '' }); } }, |
| 132 |
{ label: __('Section Background','blockenberg'),value: attr.sectionBg, onChange: function (v) { setAttr({ sectionBg: v || '' }); } } |
| 133 |
] |
| 134 |
}) |
| 135 |
), |
| 136 |
el(EditorPreview, { attr: attr }) |
| 137 |
); |
| 138 |
}, |
| 139 |
save: function (props) { |
| 140 |
var attr = props.attributes; |
| 141 |
return el('div', useBlockProps.save(), |
| 142 |
el('div', { |
| 143 |
className: 'bkbg-mt-app', |
| 144 |
'data-opts': JSON.stringify(attr) |
| 145 |
}) |
| 146 |
); |
| 147 |
} |
| 148 |
}); |
| 149 |
}() ); |
| 150 |
|