| 1 |
( function () { |
| 2 |
var el = React.createElement; |
| 3 |
var registerBlockType = wp.blocks.registerBlockType; |
| 4 |
var useBlockProps = wp.blockEditor.useBlockProps; |
| 5 |
var InspectorControls = wp.blockEditor.InspectorControls; |
| 6 |
var PanelBody = wp.components.PanelBody; |
| 7 |
var RangeControl = wp.components.RangeControl; |
| 8 |
var SelectControl = wp.components.SelectControl; |
| 9 |
var TextControl = wp.components.TextControl; |
| 10 |
var ToggleControl = wp.components.ToggleControl; |
| 11 |
var PanelColorSettings = wp.blockEditor.PanelColorSettings; |
| 12 |
|
| 13 |
var _tc, _tv; |
| 14 |
function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); } |
| 15 |
function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); } |
| 16 |
|
| 17 |
var EASING_OPTS = [ |
| 18 |
{ value: 'ease-out', label: 'Ease Out' }, |
| 19 |
{ value: 'ease-in', label: 'Ease In' }, |
| 20 |
{ value: 'linear', label: 'Linear' }, |
| 21 |
{ value: 'spring', label: 'Spring' } |
| 22 |
]; |
| 23 |
|
| 24 |
function EditorPreview(props) { |
| 25 |
var a = props.attr; |
| 26 |
var grad = a.useGradient |
| 27 |
? 'linear-gradient(90deg, '+(a.particleColor||'#7c3aed')+', '+(a.particleColor2||'#ec4899')+')' |
| 28 |
: (a.particleColor||'#7c3aed'); |
| 29 |
return el('div', { |
| 30 |
style: { background:a.bgColor||'#0a0a0f', padding:(a.paddingTop||80)+'px 40px '+(a.paddingBottom||80)+'px', textAlign:'center', borderRadius:8 } |
| 31 |
}, |
| 32 |
el('div', { |
| 33 |
style: { |
| 34 |
fontSize: (a.sampleFontSize||100)+'px', |
| 35 |
fontWeight: a.fontWeight||'900', |
| 36 |
fontFamily: a.fontFamily||'system-ui, sans-serif', |
| 37 |
background: grad, |
| 38 |
WebkitBackgroundClip: 'text', |
| 39 |
backgroundClip: 'text', |
| 40 |
WebkitTextFillColor: a.useGradient ? 'transparent' : 'unset', |
| 41 |
color: a.useGradient ? 'transparent' : (a.particleColor||'#7c3aed'), |
| 42 |
lineHeight: 1, |
| 43 |
marginBottom: 16 |
| 44 |
} |
| 45 |
}, a.text || 'BLOCKENBERG'), |
| 46 |
a.subtext && el('p', { |
| 47 |
className: 'bkbg-pt-subtext', |
| 48 |
style: { color:a.subtextColor||'#94a3b8', margin:0 } |
| 49 |
}, a.subtext) |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
registerBlockType('blockenberg/particle-text', { |
| 54 |
title: 'Particle Text', |
| 55 |
icon: 'format-quote', |
| 56 |
category: 'bkbg-effects', |
| 57 |
|
| 58 |
edit: function (props) { |
| 59 |
var attr = props.attributes; var setAttr = props.setAttributes; |
| 60 |
|
| 61 |
return el(React.Fragment, null, |
| 62 |
el(InspectorControls, null, |
| 63 |
el(PanelBody, {title:'Content', initialOpen:true}, |
| 64 |
el(TextControl,{__nextHasNoMarginBottom:true,label:'Particle Text',help:'Keep short for best effect.',value:attr.text,onChange:function(v){setAttr({text:v});}}), |
| 65 |
el(TextControl,{__nextHasNoMarginBottom:true,label:'Subtext (below canvas)',value:attr.subtext,onChange:function(v){setAttr({subtext:v});}}), |
| 66 |
), |
| 67 |
el(PanelBody, {title:'Particle Settings', initialOpen:true}, |
| 68 |
el(RangeControl,{__nextHasNoMarginBottom:true,label:'Particle Size (px)',value:attr.particleSize,min:1,max:6,step:0.5,onChange:function(v){setAttr({particleSize:v});}}), |
| 69 |
el(RangeControl,{__nextHasNoMarginBottom:true,label:'Particle Gap (px)',help:'Distance between sampled pixels.',value:attr.particleGap,min:2,max:12,onChange:function(v){setAttr({particleGap:v});}}) |
| 70 |
), |
| 71 |
el(PanelBody, {title:'Animation', initialOpen:false}, |
| 72 |
el(RangeControl,{__nextHasNoMarginBottom:true,label:'Scatter Radius (px)',value:attr.scatterRadius,min:50,max:2000,onChange:function(v){setAttr({scatterRadius:v});}}), |
| 73 |
el(RangeControl,{__nextHasNoMarginBottom:true,label:'Assemble Duration (ms)',value:attr.enterDuration,min:200,max:5000,step:100,onChange:function(v){setAttr({enterDuration:v});}}), |
| 74 |
el(SelectControl,{__nextHasNoMarginBottom:true,label:'Easing',value:attr.easing,options:EASING_OPTS,onChange:function(v){setAttr({easing:v});}}), |
| 75 |
el(ToggleControl,{__nextHasNoMarginBottom:true,label:'Hover Scatter Effect',checked:attr.hoverEffect,onChange:function(v){setAttr({hoverEffect:v});}}), |
| 76 |
attr.hoverEffect && el(RangeControl,{__nextHasNoMarginBottom:true,label:'Hover Radius (px)',value:attr.hoverRadius,min:20,max:300,onChange:function(v){setAttr({hoverRadius:v});}}) |
| 77 |
), |
| 78 |
el(PanelBody, {title:'Sizing', initialOpen:false}, |
| 79 |
el(RangeControl,{__nextHasNoMarginBottom:true,label:'Canvas Height (px)',value:attr.canvasHeight,min:100,max:1000,onChange:function(v){setAttr({canvasHeight:v});}}), |
| 80 |
el(RangeControl,{__nextHasNoMarginBottom:true,label:'Padding Top (px)',value:attr.paddingTop,min:0,max:200,onChange:function(v){setAttr({paddingTop:v});}}), |
| 81 |
el(RangeControl,{__nextHasNoMarginBottom:true,label:'Padding Bottom (px)',value:attr.paddingBottom,min:0,max:200,onChange:function(v){setAttr({paddingBottom:v});}}) |
| 82 |
), |
| 83 |
el(PanelColorSettings, { |
| 84 |
title:'Colors',initialOpen:false, |
| 85 |
colorSettings:[ |
| 86 |
{value:attr.bgColor, onChange:function(v){setAttr({bgColor: v||'#0a0a0f'});},label:'Background'}, |
| 87 |
{value:attr.particleColor, onChange:function(v){setAttr({particleColor: v||'#7c3aed'});},label:'Particle Color 1'}, |
| 88 |
{value:attr.particleColor2,onChange:function(v){setAttr({particleColor2:v||'#ec4899'});},label:'Particle Color 2 (gradient end)'}, |
| 89 |
{value:attr.subtextColor, onChange:function(v){setAttr({subtextColor: v||'#94a3b8'});},label:'Subtext Color'} |
| 90 |
] |
| 91 |
}), |
| 92 |
|
| 93 |
el( PanelBody, { title: 'Typography', initialOpen: false }, |
| 94 |
el(TextControl,{__nextHasNoMarginBottom:true,label:'Font Family',value:attr.fontFamily,onChange:function(v){setAttr({fontFamily:v});}}), |
| 95 |
el(SelectControl,{__nextHasNoMarginBottom:true,label:'Font Weight',value:attr.fontWeight,options:['300','400','500','600','700','800','900'].map(function(w){return{value:w,label:w};}),onChange:function(v){setAttr({fontWeight:v});}}), |
| 96 |
el(RangeControl,{__nextHasNoMarginBottom:true,label:'Sample Font Size (px)',help:'Larger = more detail with finer gap.',value:attr.sampleFontSize,min:40,max:300,onChange:function(v){setAttr({sampleFontSize:v});}}), |
| 97 |
el( getTypoControl(), { label: 'Subtext', value: attr.subtextTypo, onChange: function(v){ setAttr({ subtextTypo: v }); } }) |
| 98 |
), |
| 99 |
el(PanelBody, {title:'Gradient Color', initialOpen:false}, |
| 100 |
el(ToggleControl,{__nextHasNoMarginBottom:true,label:'Use Gradient',checked:attr.useGradient,onChange:function(v){setAttr({useGradient:v});}}) |
| 101 |
) |
| 102 |
), |
| 103 |
el('div', useBlockProps((function() { |
| 104 |
var tv = getTypoCssVars(); |
| 105 |
var s = {}; |
| 106 |
Object.assign(s, tv(attr.subtextTypo, '--bkbg-pt-st-')); |
| 107 |
return { style: s }; |
| 108 |
})()), el(EditorPreview, {attr:attr})) |
| 109 |
); |
| 110 |
}, |
| 111 |
|
| 112 |
save: function (props) { |
| 113 |
return el('div', useBlockProps.save(), |
| 114 |
el('div', { className:'bkbg-pt-app', 'data-opts':JSON.stringify(props.attributes) }) |
| 115 |
); |
| 116 |
} |
| 117 |
}); |
| 118 |
}() ); |
| 119 |
|