| 1 |
(function () { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
var _typoKeys = { |
| 5 |
family:'font-family', weight:'font-weight', style:'font-style', |
| 6 |
decoration:'text-decoration', transform:'text-transform', |
| 7 |
sizeDesktop:'font-size-d', sizeTablet:'font-size-t', sizeMobile:'font-size-m', |
| 8 |
lineHeightDesktop:'line-height-d', lineHeightTablet:'line-height-t', lineHeightMobile:'line-height-m', |
| 9 |
letterSpacingDesktop:'letter-spacing-d', letterSpacingTablet:'letter-spacing-t', letterSpacingMobile:'letter-spacing-m', |
| 10 |
wordSpacingDesktop:'word-spacing-d', wordSpacingTablet:'word-spacing-t', wordSpacingMobile:'word-spacing-m' |
| 11 |
}; |
| 12 |
function typoCssVarsForEl(el, obj, prefix) { |
| 13 |
if (!obj || typeof obj !== 'object') return; |
| 14 |
Object.keys(_typoKeys).forEach(function (k) { |
| 15 |
var v = obj[k]; |
| 16 |
if (v === undefined || v === '' || v === null) return; |
| 17 |
if (k === 'sizeDesktop' || k === 'sizeTablet' || k === 'sizeMobile') v = v + (obj.sizeUnit || 'px'); |
| 18 |
else if (k === 'lineHeightDesktop' || k === 'lineHeightTablet' || k === 'lineHeightMobile') v = v + (obj.lineHeightUnit || ''); |
| 19 |
else if (k === 'letterSpacingDesktop' || k === 'letterSpacingTablet' || k === 'letterSpacingMobile') v = v + (obj.letterSpacingUnit || 'px'); |
| 20 |
else if (k === 'wordSpacingDesktop' || k === 'wordSpacingTablet' || k === 'wordSpacingMobile') v = v + (obj.wordSpacingUnit || 'px'); |
| 21 |
el.style.setProperty(prefix + _typoKeys[k], String(v)); |
| 22 |
}); |
| 23 |
} |
| 24 |
|
| 25 |
var COLORS = ['strengthsColor', 'weaknessesColor', 'opportunitiesColor', 'threatsColor']; |
| 26 |
|
| 27 |
function hexToRgba(hex, alpha) { |
| 28 |
if (!hex || hex.length < 7) return 'rgba(0,0,0,' + alpha + ')'; |
| 29 |
var r = parseInt(hex.slice(1, 3), 16); |
| 30 |
var g = parseInt(hex.slice(3, 5), 16); |
| 31 |
var b = parseInt(hex.slice(5, 7), 16); |
| 32 |
return 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')'; |
| 33 |
} |
| 34 |
|
| 35 |
function getBullet(listStyle, idx) { |
| 36 |
if (listStyle === 'number') return (idx + 1) + '.'; |
| 37 |
if (listStyle === 'check') return '✓'; |
| 38 |
if (listStyle === 'dash') return '—'; |
| 39 |
if (listStyle === 'none') return ''; |
| 40 |
return '•'; |
| 41 |
} |
| 42 |
|
| 43 |
function mk(tag, cls, styles) { |
| 44 |
var d = document.createElement(tag); |
| 45 |
if (cls) d.className = cls; |
| 46 |
if (styles) Object.keys(styles).forEach(function (k) { d.style[k] = styles[k]; }); |
| 47 |
return d; |
| 48 |
} |
| 49 |
|
| 50 |
function mkText(tag, cls, text, styles) { |
| 51 |
var d = mk(tag, cls, styles); |
| 52 |
d.textContent = text; |
| 53 |
return d; |
| 54 |
} |
| 55 |
|
| 56 |
function init() { |
| 57 |
document.querySelectorAll('.bkbg-swot-analysis-app').forEach(function (appEl) { |
| 58 |
if (appEl.dataset.rendered) return; |
| 59 |
appEl.dataset.rendered = '1'; |
| 60 |
|
| 61 |
var opts; try { opts = JSON.parse(appEl.dataset.opts || '{}'); } catch (e) { opts = {}; } |
| 62 |
|
| 63 |
var defaultQuadrants = [ |
| 64 |
{ id: 'strengths', label: 'Strengths', icon: '💪', items: ['Strength item 1', 'Strength item 2'] }, |
| 65 |
{ id: 'weaknesses', label: 'Weaknesses', icon: '⚠️', items: ['Weakness item 1', 'Weakness item 2'] }, |
| 66 |
{ id: 'opportunities', label: 'Opportunities', icon: '🚀', items: ['Opportunity item 1', 'Opportunity item 2'] }, |
| 67 |
{ id: 'threats', label: 'Threats', icon: '🛡️', items: ['Threat item 1', 'Threat item 2'] } |
| 68 |
]; |
| 69 |
|
| 70 |
var o = { |
| 71 |
blockTitle: opts.blockTitle || 'SWOT Analysis', |
| 72 |
showTitle: opts.showTitle !== false, |
| 73 |
quadrants: opts.quadrants || defaultQuadrants, |
| 74 |
showIcons: opts.showIcons !== false, |
| 75 |
listStyle: opts.listStyle || 'bullet', |
| 76 |
borderRadius: opts.borderRadius !== undefined ? opts.borderRadius : 12, |
| 77 |
gap: opts.gap !== undefined ? opts.gap : 16, |
| 78 |
headerPaddingV: opts.headerPaddingV !== undefined ? opts.headerPaddingV : 16, |
| 79 |
headerPaddingH: opts.headerPaddingH !== undefined ? opts.headerPaddingH : 20, |
| 80 |
bodyPaddingV: opts.bodyPaddingV !== undefined ? opts.bodyPaddingV : 16, |
| 81 |
bodyPaddingH: opts.bodyPaddingH !== undefined ? opts.bodyPaddingH : 20, |
| 82 |
headerFontSize: opts.headerFontSize !== undefined ? opts.headerFontSize : 16, |
| 83 |
headerFontWeight: opts.headerFontWeight !== undefined ? opts.headerFontWeight : 700, |
| 84 |
itemFontSize: opts.itemFontSize !== undefined ? opts.itemFontSize : 14, |
| 85 |
titleFontSize: opts.titleFontSize !== undefined ? opts.titleFontSize : 24, |
| 86 |
enableShadow: opts.enableShadow !== false, |
| 87 |
strengthsColor: opts.strengthsColor || '#22c55e', |
| 88 |
weaknessesColor: opts.weaknessesColor || '#ef4444', |
| 89 |
opportunitiesColor:opts.opportunitiesColor|| '#3b82f6', |
| 90 |
threatsColor: opts.threatsColor || '#f59e0b', |
| 91 |
bgColor: opts.bgColor || '#ffffff', |
| 92 |
borderColor: opts.borderColor || '#e2e8f0', |
| 93 |
titleColor: opts.titleColor || '#1e293b', |
| 94 |
textColor: opts.textColor || '#374151', |
| 95 |
headerTextColor: opts.headerTextColor || '#ffffff' |
| 96 |
}; |
| 97 |
|
| 98 |
var quadColors = [o.strengthsColor, o.weaknessesColor, o.opportunitiesColor, o.threatsColor]; |
| 99 |
|
| 100 |
/* ── Outer block ─────────────────────────────────── */ |
| 101 |
var block = mk('div', 'bkbg-swot-block'); |
| 102 |
|
| 103 |
typoCssVarsForEl(block, o.titleTypo, '--bkswa-tt-'); |
| 104 |
typoCssVarsForEl(block, o.headerTypo, '--bkswa-ht-'); |
| 105 |
typoCssVarsForEl(block, o.itemTypo, '--bkswa-it-'); |
| 106 |
|
| 107 |
/* ── Title ───────────────────────────────────────── */ |
| 108 |
if (o.showTitle && o.blockTitle) { |
| 109 |
var titleEl = mkText('h3', 'bkbg-swot-title', o.blockTitle, { |
| 110 |
color: o.titleColor |
| 111 |
}); |
| 112 |
block.appendChild(titleEl); |
| 113 |
} |
| 114 |
|
| 115 |
/* ── Grid ────────────────────────────────────────── */ |
| 116 |
var grid = mk('div', 'bkbg-swot-grid', { gap: o.gap + 'px' }); |
| 117 |
block.appendChild(grid); |
| 118 |
|
| 119 |
o.quadrants.forEach(function (quad, i) { |
| 120 |
var color = quadColors[i] || '#3b82f6'; |
| 121 |
var bodyBg = hexToRgba(color, 0.06); |
| 122 |
var borderCol = hexToRgba(color, 0.3); |
| 123 |
|
| 124 |
/* Quadrant card */ |
| 125 |
var card = mk('div', 'bkbg-swot-quadrant', { |
| 126 |
background: o.bgColor, |
| 127 |
border: '1px solid ' + borderCol, |
| 128 |
borderRadius: o.borderRadius + 'px', |
| 129 |
boxShadow: o.enableShadow ? '0 2px 12px rgba(0,0,0,0.07)' : 'none' |
| 130 |
}); |
| 131 |
|
| 132 |
/* Header */ |
| 133 |
var header = mk('div', 'bkbg-swot-header', { |
| 134 |
background: color, |
| 135 |
padding: o.headerPaddingV + 'px ' + o.headerPaddingH + 'px', |
| 136 |
color: o.headerTextColor |
| 137 |
}); |
| 138 |
|
| 139 |
if (o.showIcons && quad.icon) { |
| 140 |
var iconEl = mkText('span', 'bkbg-swot-icon', quad.icon); |
| 141 |
header.appendChild(iconEl); |
| 142 |
} |
| 143 |
|
| 144 |
var labelEl = mkText('span', 'bkbg-swot-label', quad.label); |
| 145 |
header.appendChild(labelEl); |
| 146 |
card.appendChild(header); |
| 147 |
|
| 148 |
/* Body */ |
| 149 |
var body = mk('div', 'bkbg-swot-body', { |
| 150 |
background: bodyBg, |
| 151 |
padding: o.bodyPaddingV + 'px ' + o.bodyPaddingH + 'px' |
| 152 |
}); |
| 153 |
|
| 154 |
(quad.items || []).forEach(function (item, itemIdx) { |
| 155 |
var row = mk('div', 'bkbg-swot-item'); |
| 156 |
|
| 157 |
var bullet = getBullet(o.listStyle, itemIdx); |
| 158 |
if (bullet) { |
| 159 |
var bulletEl = mkText('span', 'bkbg-swot-bullet', bullet, { |
| 160 |
color: color |
| 161 |
}); |
| 162 |
row.appendChild(bulletEl); |
| 163 |
} |
| 164 |
|
| 165 |
var textEl = mkText('span', 'bkbg-swot-item-text', item, { |
| 166 |
color: o.textColor |
| 167 |
}); |
| 168 |
row.appendChild(textEl); |
| 169 |
body.appendChild(row); |
| 170 |
}); |
| 171 |
|
| 172 |
card.appendChild(body); |
| 173 |
grid.appendChild(card); |
| 174 |
}); |
| 175 |
|
| 176 |
/* ── Insert & hide placeholder ───────────────────── */ |
| 177 |
appEl.parentNode.insertBefore(block, appEl); |
| 178 |
appEl.style.display = 'none'; |
| 179 |
}); |
| 180 |
} |
| 181 |
|
| 182 |
if (document.readyState !== 'loading') { init(); } |
| 183 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 184 |
})(); |
| 185 |
|