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 / font-scale / index.js

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

157 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 const el = window.wp.element.createElement;
3 const { registerBlockType } = window.wp.blocks;
4 const { InspectorControls, useBlockProps, PanelColorSettings } = window.wp.blockEditor;
5 const { PanelBody, RangeControl, SelectControl, ToggleControl, TextControl, Button } = window.wp.components;
6 const { __ } = window.wp.i18n;
7
8 var _fsTC, _fsTV;
9 function _tc() { return _fsTC || (_fsTC = window.bkbgTypographyControl); }
10 function _tv() { return _fsTV || (_fsTV = window.bkbgTypoCssVars); }
11
12 const FONT_OPTIONS = [
13 { value: 'inherit', label: 'Theme default' },
14 { value: '-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif', label: 'System UI (San Francisco / Segoe)' },
15 { value: 'Georgia, "Times New Roman", serif', label: 'Georgia (Serif)' },
16 { value: '"Courier New", Courier, monospace', label: 'Courier (Mono)' },
17 { value: 'Arial, Helvetica, sans-serif', label: 'Arial / Helvetica' },
18 { value: '"Palatino Linotype", Palatino, serif', label: 'Palatino (Serif)' },
19 { value: '"Trebuchet MS", sans-serif', label: 'Trebuchet MS' },
20 { value: 'Verdana, Geneva, sans-serif', label: 'Verdana' },
21 ];
22
23 function updStep(steps, idx, field, val) {
24 return steps.map((s, i) => i === idx ? { ...s, [field]: val } : s);
25 }
26
27 // ── Render the scale ──────────────────────────────────────────────
28 function renderScale(a) {
29 const ff = a.fontFamily === 'inherit' ? 'inherit' : a.fontFamily;
30 return el('div', { className: 'bkbg-fs-scale' },
31 a.steps.map((step, i) => {
32 const metaEl = a.showMeta && el('div', {
33 className: 'bkbg-fs-meta',
34 style: { color: a.metaColor, fontSize: '12px', lineHeight: 1.6, flexShrink: 0, display: 'flex', flexDirection: 'column', gap: '2px', alignItems: 'flex-end', minWidth: '80px', paddingTop: '4px' }
35 },
36 el('span', { style: { fontWeight: 600 } }, step.size + 'px'),
37 el('span', null, step.weight),
38 el('span', null, 'lh ' + step.lineHeight),
39 );
40
41 return el('div', {
42 key: i,
43 className: 'bkbg-fs-row',
44 style: {
45 display: 'flex', alignItems: 'flex-start', gap: '16px',
46 padding: '16px 0',
47 borderBottom: a.showDividers ? '1px solid ' + a.dividerColor : 'none',
48 }
49 },
50 // Step name badge
51 el('div', {
52 style: {
53 background: a.nameBg, color: a.nameColor,
54 fontSize: '11px', fontWeight: 700, letterSpacing: '0.05em',
55 padding: '3px 8px', borderRadius: '6px',
56 flexShrink: 0, alignSelf: 'flex-start', marginTop: '6px',
57 fontFamily: '-apple-system, sans-serif',
58 minWidth: '44px', textAlign: 'center',
59 }
60 }, step.name),
61 // Sample text
62 el('div', {
63 className: 'bkbg-fs-sample',
64 style: {
65 flex: 1,
66 fontFamily: ff,
67 fontSize: step.size + 'px',
68 fontWeight: step.weight,
69 lineHeight: step.lineHeight,
70 color: a.textColor,
71 wordBreak: 'break-word',
72 minWidth: 0,
73 }
74 }, step.text),
75 // Meta (right side)
76 a.metaPosition === 'right' && metaEl,
77 );
78 })
79 );
80 }
81
82 function wrapStyle(a) {
83 return Object.assign(
84 { background: a.bgColor, borderRadius: a.borderRadius + 'px', paddingTop: a.paddingTop + 'px', paddingBottom: a.paddingBottom + 'px', paddingLeft: '36px', paddingRight: '36px' },
85 _tv()(a.typoTitle, '--bkbg-fs-tt-'),
86 _tv()(a.typoSubtitle, '--bkbg-fs-ts-')
87 );
88 }
89
90 registerBlockType('blockenberg/font-scale', {
91 edit: function ({ attributes: a, setAttributes }) {
92 const blockProps = useBlockProps({ style: wrapStyle(a) });
93 return el('div', blockProps,
94 el(InspectorControls, {},
95 el(PanelBody, { title: __('Content'), initialOpen: true },
96 el(TextControl, { label: __('Title'), value: a.title, onChange: v => setAttributes({ title: v }) }),
97 el(ToggleControl, { label: __('Show title'), checked: a.showTitle, onChange: v => setAttributes({ showTitle: v }) }),
98 el(TextControl, { label: __('Subtitle'), value: a.subtitle, onChange: v => setAttributes({ subtitle: v }) }),
99 el(ToggleControl, { label: __('Show subtitle'), checked: a.showSubtitle, onChange: v => setAttributes({ showSubtitle: v }) }),
100 el(ToggleControl, { label: __('Show size/weight meta'), checked: a.showMeta, onChange: v => setAttributes({ showMeta: v }) }),
101 el(ToggleControl, { label: __('Show row dividers'), checked: a.showDividers, onChange: v => setAttributes({ showDividers: v }) }),
102 ),
103 el(PanelBody, { title: __('Scale Steps'), initialOpen: false },
104 a.steps.map((step, i) =>
105 el(PanelBody, { key: i, title: step.name + '' + step.size + 'px', initialOpen: false },
106 el(TextControl, { label: __('Step name'), value: step.name, onChange: v => setAttributes({ steps: updStep(a.steps, i, 'name', v) }) }),
107 el(RangeControl, { label: __('Size (px)'), value: step.size, min: 8, max: 128, onChange: v => setAttributes({ steps: updStep(a.steps, i, 'size', v) }) }),
108 el(RangeControl, { label: __('Weight'), value: step.weight, min: 100, max: 900, step: 100, onChange: v => setAttributes({ steps: updStep(a.steps, i, 'weight', v) }) }),
109 el(RangeControl, { label: __('Line height (×10)'), value: Math.round(step.lineHeight * 10), min: 8, max: 25, onChange: v => setAttributes({ steps: updStep(a.steps, i, 'lineHeight', v / 10) }) }),
110 el(TextControl, { label: __('Sample text'), value: step.text, onChange: v => setAttributes({ steps: updStep(a.steps, i, 'text', v) }) }),
111 el(Button, { variant: 'secondary', isDestructive: true, onClick: () => { const s = a.steps.slice(); s.splice(i, 1); setAttributes({ steps: s }); } }, __('Remove step')),
112 )
113 ),
114 el(Button, { variant: 'primary', onClick: () => setAttributes({ steps: a.steps.concat([{ name: 'new', size: 16, weight: 400, lineHeight: 1.5, text: 'Sample text' }]) }) }, __('+ Add step')),
115 ),
116 el(PanelBody, { title: __('Spacing & Style'), initialOpen: false },
117 el(RangeControl, { label: __('Border radius'), value: a.borderRadius, min: 0, max: 32, onChange: v => setAttributes({ borderRadius: v }) }),
118 el(RangeControl, { label: __('Padding top'), value: a.paddingTop, min: 0, max: 120, onChange: v => setAttributes({ paddingTop: v }) }),
119 el(RangeControl, { label: __('Padding bottom'), value: a.paddingBottom, min: 0, max: 120, onChange: v => setAttributes({ paddingBottom: v }) }),
120 ),
121
122 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
123 el(SelectControl, { label: __('Specimen Font Family'), value: a.fontFamily, options: FONT_OPTIONS, onChange: v => setAttributes({ fontFamily: v }) }),
124 _tc()({ label: __('Title', 'blockenberg'), value: a.typoTitle, onChange: v => setAttributes({ typoTitle: v }) }),
125 _tc()({ label: __('Subtitle', 'blockenberg'), value: a.typoSubtitle, onChange: v => setAttributes({ typoSubtitle: v }) })
126 ),
127 el(PanelColorSettings, {
128 title: __('Colors'), initialOpen: false,
129 colorSettings: [
130 { label: __('Background'), value: a.bgColor, onChange: v => setAttributes({ bgColor: v || '#ffffff' }) },
131 { label: __('Title'), value: a.titleColor, onChange: v => setAttributes({ titleColor: v || '#0f172a' }) },
132 { label: __('Subtitle'), value: a.subtitleColor, onChange: v => setAttributes({ subtitleColor: v || '#64748b' }) },
133 { label: __('Sample text'), value: a.textColor, onChange: v => setAttributes({ textColor: v || '#0f172a' }) },
134 { label: __('Meta text'), value: a.metaColor, onChange: v => setAttributes({ metaColor: v || '#94a3b8' }) },
135 { label: __('Name badge BG'),value: a.nameBg, onChange: v => setAttributes({ nameBg: v || '#f1f5f9' }) },
136 { label: __('Name badge text'), value: a.nameColor, onChange: v => setAttributes({ nameColor: v || '#475569' }) },
137 { label: __('Divider'), value: a.dividerColor, onChange: v => setAttributes({ dividerColor: v || '#f1f5f9' }) },
138 ]
139 }),
140 ),
141
142 a.showTitle && el('h3', { className: 'bkbg-fs-title', style: { color: a.titleColor, margin: '0 0 8px' } }, a.title),
143 a.showSubtitle && el('p', { className: 'bkbg-fs-subtitle', style: { color: a.subtitleColor, margin: '0 0 24px' } }, a.subtitle),
144 renderScale(a),
145 );
146 },
147
148 save: function ({ attributes: a }) {
149 return el('div', { className: 'bkbg-fs-wrap', style: wrapStyle(a) },
150 a.showTitle && el('h3', { className: 'bkbg-fs-title', style: { color: a.titleColor, margin: '0 0 8px' } }, a.title),
151 a.showSubtitle && el('p', { className: 'bkbg-fs-subtitle', style: { color: a.subtitleColor, margin: '0 0 24px' } }, a.subtitle),
152 renderScale(a),
153 );
154 }
155 });
156 }() );
157