| 1 |
(function () { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
function mk(tag, cls, styles) { |
| 5 |
var d = document.createElement(tag); |
| 6 |
if (cls) d.className = cls; |
| 7 |
if (styles) Object.keys(styles).forEach(function (k) { d.style[k] = styles[k]; }); |
| 8 |
return d; |
| 9 |
} |
| 10 |
function tx(tag, cls, text, styles) { |
| 11 |
var d = mk(tag, cls, styles); |
| 12 |
d.textContent = text; |
| 13 |
return d; |
| 14 |
} |
| 15 |
function ap(parent) { |
| 16 |
Array.prototype.slice.call(arguments, 1).forEach(function (c) { if (c) parent.appendChild(c); }); |
| 17 |
return parent; |
| 18 |
} |
| 19 |
|
| 20 |
function releaseTypeInfo(t) { |
| 21 |
if (t === 'major') return { label: '🚀 Major', bg: '#fee2e2', color: '#991b1b' }; |
| 22 |
if (t === 'patch') return { label: '🐛 Patch', bg: '#fef9c3', color: '#713f12' }; |
| 23 |
if (t === 'hotfix') return { label: '🔥 Hotfix', bg: '#ffedd5', color: '#9a3412' }; |
| 24 |
return { label: '✨ Minor', bg: '#dbeafe', color: '#1e3a8a' }; |
| 25 |
} |
| 26 |
|
| 27 |
function sectionMeta(type, o) { |
| 28 |
if (type === 'added') return { label: 'Added', bg: o.addedBg, color: o.addedColor, dot: '#16a34a' }; |
| 29 |
if (type === 'changed') return { label: 'Changed', bg: o.changedBg, color: o.changedColor, dot: '#2563eb' }; |
| 30 |
if (type === 'fixed') return { label: 'Fixed', bg: o.fixedBg, color: o.fixedColor, dot: '#ca8a04' }; |
| 31 |
if (type === 'removed') return { label: 'Removed', bg: o.removedBg, color: o.removedColor, dot: '#dc2626' }; |
| 32 |
if (type === 'security') return { label: 'Security', bg: o.securityBg, color: o.securityColor, dot: '#7c3aed' }; |
| 33 |
if (type === 'deprecated') return { label: 'Deprecated', bg: o.deprecatedBg, color: o.deprecatedColor, dot: '#64748b' }; |
| 34 |
return { label: type, bg: '#f1f5f9', color: '#374151', dot: '#64748b' }; |
| 35 |
} |
| 36 |
|
| 37 |
var _typoKeys = { |
| 38 |
family:'font-family', weight:'font-weight', style:'font-style', |
| 39 |
decoration:'text-decoration', transform:'text-transform', |
| 40 |
sizeDesktop:'font-size-d', sizeTablet:'font-size-t', sizeMobile:'font-size-m', |
| 41 |
lineHeightDesktop:'line-height-d', lineHeightTablet:'line-height-t', lineHeightMobile:'line-height-m', |
| 42 |
letterSpacingDesktop:'letter-spacing-d', letterSpacingTablet:'letter-spacing-t', letterSpacingMobile:'letter-spacing-m', |
| 43 |
wordSpacingDesktop:'word-spacing-d', wordSpacingTablet:'word-spacing-t', wordSpacingMobile:'word-spacing-m' |
| 44 |
}; |
| 45 |
function typoCssVarsForEl(typo, prefix, el) { |
| 46 |
if (!typo || typeof typo !== 'object') return; |
| 47 |
Object.keys(_typoKeys).forEach(function(k) { |
| 48 |
if (typo[k] !== undefined && typo[k] !== '') { |
| 49 |
var v = typo[k]; |
| 50 |
if (['sizeDesktop','sizeTablet','sizeMobile'].indexOf(k) !== -1) v = v + (typo.sizeUnit || 'px'); |
| 51 |
else if (['lineHeightDesktop','lineHeightTablet','lineHeightMobile'].indexOf(k) !== -1) v = v + (typo.lineHeightUnit || ''); |
| 52 |
else if (['letterSpacingDesktop','letterSpacingTablet','letterSpacingMobile'].indexOf(k) !== -1) v = v + (typo.letterSpacingUnit || 'px'); |
| 53 |
else if (['wordSpacingDesktop','wordSpacingTablet','wordSpacingMobile'].indexOf(k) !== -1) v = v + (typo.wordSpacingUnit || 'px'); |
| 54 |
el.style.setProperty(prefix + _typoKeys[k], String(v)); |
| 55 |
} |
| 56 |
}); |
| 57 |
} |
| 58 |
|
| 59 |
function init() { |
| 60 |
document.querySelectorAll('.bkbg-release-notes-app').forEach(function (appEl) { |
| 61 |
if (appEl.dataset.rendered) return; |
| 62 |
appEl.dataset.rendered = '1'; |
| 63 |
|
| 64 |
var opts; |
| 65 |
try { opts = JSON.parse(appEl.dataset.opts || '{}'); } catch (e) { opts = {}; } |
| 66 |
|
| 67 |
var o = Object.assign({ |
| 68 |
productName: 'Product', version: '1.0.0', releaseDate: '', |
| 69 |
releaseType: 'minor', showMeta: true, showReleaseType: true, |
| 70 |
intro: '', showIntro: true, sections: [], |
| 71 |
changelogUrl: '', compareUrl: '', showLinks: true, |
| 72 |
fontSize: 14, titleFontSize: 24, lineHeight: 168, |
| 73 |
borderRadius: 10, itemSpacing: 6, |
| 74 |
bgColor: '#ffffff', borderColor: '#e5e7eb', |
| 75 |
headerBg: '#0f172a', headerColor: '#ffffff', |
| 76 |
introBg: '#f8fafc', introColor: '#374151', textColor: '#374151', |
| 77 |
accentColor: '#3b82f6', |
| 78 |
addedBg: '#dcfce7', addedColor: '#14532d', |
| 79 |
changedBg: '#dbeafe', changedColor: '#1e3a8a', |
| 80 |
fixedBg: '#fef9c3', fixedColor: '#713f12', |
| 81 |
removedBg: '#fee2e2', removedColor: '#991b1b', |
| 82 |
securityBg: '#f3e8ff', securityColor: '#581c87', |
| 83 |
deprecatedBg: '#f1f5f9', deprecatedColor: '#475569' |
| 84 |
}, opts); |
| 85 |
|
| 86 |
// Block wrapper |
| 87 |
var block = mk('div', 'bkbg-rn-block', { |
| 88 |
border: '1px solid ' + o.borderColor, |
| 89 |
borderRadius: o.borderRadius + 'px', |
| 90 |
overflow: 'hidden', |
| 91 |
background: o.bgColor |
| 92 |
}); |
| 93 |
typoCssVarsForEl(o.titleTypo, '--bkrn-tt-', block); |
| 94 |
typoCssVarsForEl(o.bodyTypo, '--bkrn-bt-', block); |
| 95 |
|
| 96 |
// ── Header ─────────────────────────────────────────── |
| 97 |
var header = mk('div', 'bkbg-rn-header', { background: o.headerBg }); |
| 98 |
var hrow = mk('div', 'bkbg-rn-header-row'); |
| 99 |
ap(hrow, tx('span', 'bkbg-rn-version', 'v' + o.version, { color: o.headerColor })); |
| 100 |
if (o.showReleaseType) { |
| 101 |
var rtI = releaseTypeInfo(o.releaseType); |
| 102 |
ap(hrow, tx('span', 'bkbg-rn-type-badge', rtI.label, { background: rtI.bg, color: rtI.color })); |
| 103 |
} |
| 104 |
ap(hrow, tx('span', 'bkbg-rn-product', o.productName, { color: o.headerColor })); |
| 105 |
ap(header, hrow); |
| 106 |
if (o.showMeta && o.releaseDate) { |
| 107 |
ap(header, tx('div', 'bkbg-rn-date', '� |
| 108 |
Released ' + o.releaseDate, { color: o.headerColor })); |
| 109 |
} |
| 110 |
ap(block, header); |
| 111 |
|
| 112 |
// ── Intro ───────────────────────────────────────────── |
| 113 |
if (o.showIntro && o.intro) { |
| 114 |
var intro = tx('div', 'bkbg-rn-intro', o.intro, { |
| 115 |
background: o.introBg, |
| 116 |
borderColor: o.borderColor, |
| 117 |
color: o.introColor |
| 118 |
}); |
| 119 |
ap(block, intro); |
| 120 |
} |
| 121 |
|
| 122 |
// ── Body ───────────────────────────────────────────── |
| 123 |
var body = mk('div', 'bkbg-rn-body'); |
| 124 |
|
| 125 |
o.sections.forEach(function (sec, si) { |
| 126 |
if (!sec || !sec.items || sec.items.length === 0) return; |
| 127 |
var m = sectionMeta(sec.type, o); |
| 128 |
|
| 129 |
var section = mk('div', 'bkbg-rn-section'); |
| 130 |
|
| 131 |
// Section heading |
| 132 |
var shead = mk('div', 'bkbg-rn-section-head'); |
| 133 |
var pill = mk('span', 'bkbg-rn-type-pill', { background: m.bg, color: m.color }); |
| 134 |
var dot = mk('span', 'bkbg-rn-type-dot', { background: m.dot }); |
| 135 |
ap(pill, dot); |
| 136 |
pill.appendChild(document.createTextNode(m.label)); |
| 137 |
ap(shead, pill); |
| 138 |
ap(shead, tx('span', 'bkbg-rn-count', sec.items.length + ' item' + (sec.items.length !== 1 ? 's' : ''))); |
| 139 |
ap(section, shead); |
| 140 |
|
| 141 |
// Items |
| 142 |
var list = mk('ul', 'bkbg-rn-list'); |
| 143 |
sec.items.forEach(function (item, ii) { |
| 144 |
var li = mk('li', 'bkbg-rn-item', { |
| 145 |
padding: o.itemSpacing + 'px 0', |
| 146 |
borderBottomColor: o.borderColor |
| 147 |
}); |
| 148 |
var dash = tx('span', 'bkbg-rn-dash', '—', { color: m.dot }); |
| 149 |
var txt = tx('span', '', item, { color: o.textColor }); |
| 150 |
ap(li, dash, txt); |
| 151 |
ap(list, li); |
| 152 |
}); |
| 153 |
ap(section, list); |
| 154 |
ap(body, section); |
| 155 |
}); |
| 156 |
|
| 157 |
// Footer links |
| 158 |
if (o.showLinks && (o.changelogUrl || o.compareUrl)) { |
| 159 |
var linksRow = mk('div', 'bkbg-rn-links', { borderTopColor: o.borderColor }); |
| 160 |
if (o.changelogUrl) { |
| 161 |
var cl = mk('a', 'bkbg-rn-link', { color: o.accentColor }); |
| 162 |
cl.href = o.changelogUrl; cl.textContent = '📋 Full Changelog →'; |
| 163 |
ap(linksRow, cl); |
| 164 |
} |
| 165 |
if (o.compareUrl) { |
| 166 |
var cr = mk('a', 'bkbg-rn-link', { color: o.accentColor }); |
| 167 |
cr.href = o.compareUrl; cr.textContent = '🔀 Compare Changes →'; |
| 168 |
ap(linksRow, cr); |
| 169 |
} |
| 170 |
ap(body, linksRow); |
| 171 |
} |
| 172 |
|
| 173 |
ap(block, body); |
| 174 |
appEl.parentNode.insertBefore(block, appEl); |
| 175 |
appEl.style.display = 'none'; |
| 176 |
}); |
| 177 |
} |
| 178 |
|
| 179 |
if (document.readyState !== 'loading') { init(); } |
| 180 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 181 |
})(); |
| 182 |
|