| 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(p) { |
| 16 |
Array.prototype.slice.call(arguments, 1).forEach(function (c) { if (c) p.appendChild(c); }); |
| 17 |
return p; |
| 18 |
} |
| 19 |
|
| 20 |
// ── helpers ──────────────────────────────────────────────────────── |
| 21 |
function fmtTime(h, m, use12) { |
| 22 |
if (!use12) { |
| 23 |
return (h < 10 ? '0' : '') + h + ':' + (m === 0 ? '00' : (m < 10 ? '0' : '') + m); |
| 24 |
} |
| 25 |
var ampm = h >= 12 ? 'PM' : 'AM'; |
| 26 |
var hh = h % 12 || 12; |
| 27 |
return hh + ':' + (m === 0 ? '00' : (m < 10 ? '0' : '') + m) + ' ' + ampm; |
| 28 |
} |
| 29 |
|
| 30 |
function catColors(cat, a) { |
| 31 |
if (cat === 'work') return { bg: a.workBg || '#1e3a5f', color: a.workColor || '#93c5fd' }; |
| 32 |
if (cat === 'break') return { bg: a.breakBg || '#14532d', color: a.breakColor || '#86efac' }; |
| 33 |
if (cat === 'personal') return { bg: a.personalBg || '#3b0764', color: a.personalColor || '#c4b5fd' }; |
| 34 |
if (cat === 'health') return { bg: a.healthBg || '#431407', color: a.healthColor || '#fdba74' }; |
| 35 |
if (cat === 'meal') return { bg: a.mealBg || '#451a03', color: a.mealColor || '#fde68a' }; |
| 36 |
return { bg: a.workBg || '#1e3a5f', color: a.workColor || '#93c5fd' }; |
| 37 |
} |
| 38 |
|
| 39 |
function catEmoji(cat) { |
| 40 |
var map = { work: '💻', break: '☕', personal: '🎨', health: '🏃', meal: '🍽️' }; |
| 41 |
return map[cat] || '📌'; |
| 42 |
} |
| 43 |
|
| 44 |
var CAT_LABELS = { work: 'Work', break: 'Break', personal: 'Personal', health: 'Health', meal: 'Meal' }; |
| 45 |
|
| 46 |
/* ── Typography CSS-var helper ─────────────────────────────────────── */ |
| 47 |
function typoCssVarsForEl(typo, prefix, el) { |
| 48 |
if (!typo || typeof typo !== 'object') return; |
| 49 |
var map = { |
| 50 |
family:'font-family', weight:'font-weight', style:'font-style', |
| 51 |
transform:'text-transform', decoration:'text-decoration', |
| 52 |
sizeDesktop:'font-size-d', sizeTablet:'font-size-t', sizeMobile:'font-size-m', sizeUnit:'font-size-unit', |
| 53 |
lineHeightDesktop:'line-height-d', lineHeightTablet:'line-height-t', lineHeightMobile:'line-height-m', lineHeightUnit:'line-height-unit', |
| 54 |
letterSpacingDesktop:'letter-spacing-d', letterSpacingTablet:'letter-spacing-t', letterSpacingMobile:'letter-spacing-m', letterSpacingUnit:'letter-spacing-unit', |
| 55 |
wordSpacingDesktop:'word-spacing-d', wordSpacingTablet:'word-spacing-t', wordSpacingMobile:'word-spacing-m', wordSpacingUnit:'word-spacing-unit' |
| 56 |
}; |
| 57 |
Object.keys(map).forEach(function(k) { |
| 58 |
if (typo[k] !== undefined && typo[k] !== '') { |
| 59 |
var v = typo[k]; |
| 60 |
var css = map[k]; |
| 61 |
if (css.indexOf('size-d') !== -1 || css.indexOf('size-t') !== -1 || css.indexOf('size-m') !== -1 || |
| 62 |
css.indexOf('height-d') !== -1 || css.indexOf('height-t') !== -1 || css.indexOf('height-m') !== -1 || |
| 63 |
css.indexOf('spacing-d') !== -1 || css.indexOf('spacing-t') !== -1 || css.indexOf('spacing-m') !== -1) { |
| 64 |
var unitKey = css.replace(/-[dtm]$/, '-unit'); |
| 65 |
var unit = ''; |
| 66 |
Object.keys(map).forEach(function(k2) { if (map[k2] === unitKey && typo[k2]) unit = typo[k2]; }); |
| 67 |
if (!unit) unit = css.indexOf('size') !== -1 ? 'px' : ''; |
| 68 |
v = v + unit; |
| 69 |
} |
| 70 |
el.style.setProperty(prefix + css, v); |
| 71 |
} |
| 72 |
}); |
| 73 |
} |
| 74 |
|
| 75 |
// ── builder ─────────────────────────────────────────────────────── |
| 76 |
function buildBlock(appEl) { |
| 77 |
if (appEl.dataset.rendered) return; |
| 78 |
appEl.dataset.rendered = '1'; |
| 79 |
var a; |
| 80 |
try { a = JSON.parse(appEl.dataset.opts || '{}'); } catch (e) { a = {}; } |
| 81 |
|
| 82 |
var hourStart = typeof a.hourStart === 'number' ? a.hourStart : 6; |
| 83 |
var hourEnd = typeof a.hourEnd === 'number' ? a.hourEnd : 22; |
| 84 |
var hourHeight = typeof a.hourHeight === 'number' ? a.hourHeight : 60; |
| 85 |
var fontSize = typeof a.fontSize === 'number' ? a.fontSize : 13; |
| 86 |
var totalHours = Math.max(hourEnd - hourStart, 1); |
| 87 |
var totalHeight = totalHours * hourHeight; |
| 88 |
var timeColW = 68; |
| 89 |
var borderRadius = typeof a.borderRadius === 'number' ? a.borderRadius : 12; |
| 90 |
|
| 91 |
// Outer wrapper |
| 92 |
var wrap = mk('div', 'bkbg-daily-schedule-app', { |
| 93 |
background: a.bgColor || '#0f172a', |
| 94 |
border: '1px solid ' + (a.borderColor || '#1e293b'), |
| 95 |
borderRadius: borderRadius + 'px', |
| 96 |
overflow: 'hidden', |
| 97 |
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif' |
| 98 |
}); |
| 99 |
|
| 100 |
// Header |
| 101 |
if (a.showTitle !== false && a.dayTitle) { |
| 102 |
var header = mk('div', 'bkbg-ds-header', { |
| 103 |
background: a.headerBg || '#1e293b', |
| 104 |
borderBottom: '1px solid ' + (a.borderColor || '#1e293b'), |
| 105 |
padding: '18px 20px 14px' |
| 106 |
}); |
| 107 |
|
| 108 |
ap(header, tx('h2', 'bkbg-ds-title', a.dayTitle, { |
| 109 |
color: a.titleColor || '#f8fafc', |
| 110 |
margin: '0 0 10px' |
| 111 |
})); |
| 112 |
|
| 113 |
// Legend |
| 114 |
var legend = mk('div', 'bkbg-ds-legend'); |
| 115 |
['work', 'break', 'personal', 'health', 'meal'].forEach(function (cat) { |
| 116 |
var cc = catColors(cat, a); |
| 117 |
var pill = mk('span', 'bkbg-ds-legend-item', { |
| 118 |
background: cc.bg, color: cc.color |
| 119 |
}); |
| 120 |
pill.textContent = catEmoji(cat) + ' ' + CAT_LABELS[cat]; |
| 121 |
legend.appendChild(pill); |
| 122 |
}); |
| 123 |
ap(header, legend); |
| 124 |
ap(wrap, header); |
| 125 |
} |
| 126 |
|
| 127 |
// Body |
| 128 |
var body = mk('div', 'bkbg-ds-body', { |
| 129 |
position: 'relative', |
| 130 |
height: (totalHeight + 24) + 'px', |
| 131 |
padding: '12px 12px 16px' |
| 132 |
}); |
| 133 |
|
| 134 |
// Hour rows (grid lines + time labels) |
| 135 |
for (var h = hourStart; h <= hourEnd; h++) { |
| 136 |
var y = (h - hourStart) * hourHeight; |
| 137 |
var row = mk('div', 'bkbg-ds-hour-row', { position: 'absolute', top: y + 'px', left: '12px', right: '12px', display: 'flex', alignItems: 'flex-start' }); |
| 138 |
|
| 139 |
ap(row, tx('span', 'bkbg-ds-time-label', fmtTime(h, 0, a.use12Hour), { |
| 140 |
width: timeColW + 'px', |
| 141 |
color: a.timeColor || '#475569', |
| 142 |
fontSize: (fontSize - 1) + 'px' |
| 143 |
})); |
| 144 |
|
| 145 |
if (a.showGridLines !== false) { |
| 146 |
ap(row, mk('span', 'bkbg-ds-grid-line', { background: a.gridLineColor || '#1e293b' })); |
| 147 |
} |
| 148 |
|
| 149 |
body.appendChild(row); |
| 150 |
} |
| 151 |
|
| 152 |
// Events |
| 153 |
(a.events || []).forEach(function (ev) { |
| 154 |
var top = ((ev.startHour - hourStart) + (ev.startMin / 60)) * hourHeight; |
| 155 |
var evH = Math.max((ev.duration / 60) * hourHeight - 4, 20); |
| 156 |
var cc = catColors(ev.category, a); |
| 157 |
var endH = ev.startHour + Math.floor((ev.startMin + ev.duration) / 60); |
| 158 |
var endM = (ev.startMin + ev.duration) % 60; |
| 159 |
var left = timeColW + 16; |
| 160 |
|
| 161 |
var evEl = mk('div', 'bkbg-ds-event', { |
| 162 |
top: top + 'px', |
| 163 |
left: left + 'px', |
| 164 |
right: '0', |
| 165 |
height: evH + 'px', |
| 166 |
background: cc.bg, |
| 167 |
borderLeft: '3px solid ' + cc.color, |
| 168 |
color: cc.color |
| 169 |
}); |
| 170 |
|
| 171 |
// Title row |
| 172 |
var titleRow = mk('div', 'bkbg-ds-event-title-row'); |
| 173 |
ap(titleRow, |
| 174 |
tx('span', '', catEmoji(ev.category), { fontSize: '13px' }), |
| 175 |
tx('span', 'bkbg-ds-event-title', ev.title, { |
| 176 |
fontSize: fontSize + 'px', |
| 177 |
color: cc.color |
| 178 |
}) |
| 179 |
); |
| 180 |
evEl.appendChild(titleRow); |
| 181 |
|
| 182 |
// Time |
| 183 |
if (a.showEventTime !== false && evH > 28) { |
| 184 |
var timeStr = fmtTime(ev.startHour, ev.startMin, a.use12Hour) + ' – ' + fmtTime(endH, endM, a.use12Hour); |
| 185 |
ap(evEl, tx('div', 'bkbg-ds-event-time', timeStr, { fontSize: (fontSize - 2) + 'px', color: cc.color })); |
| 186 |
} |
| 187 |
|
| 188 |
// Note |
| 189 |
if (a.showEventNote !== false && ev.note && evH > 48) { |
| 190 |
ap(evEl, tx('div', 'bkbg-ds-event-note', ev.note, { fontSize: (fontSize - 2) + 'px', color: cc.color })); |
| 191 |
} |
| 192 |
|
| 193 |
body.appendChild(evEl); |
| 194 |
}); |
| 195 |
|
| 196 |
ap(wrap, body); |
| 197 |
|
| 198 |
/* Apply typography CSS vars on wrap */ |
| 199 |
wrap.style.setProperty('--bkbg-ds-ttl-fs', (a.titleFontSize || 22) + 'px'); |
| 200 |
typoCssVarsForEl(a.typoTitle, '--bkbg-ds-ttl-', wrap); |
| 201 |
|
| 202 |
appEl.innerHTML = ''; |
| 203 |
appEl.appendChild(wrap); |
| 204 |
} |
| 205 |
|
| 206 |
function init() { |
| 207 |
document.querySelectorAll('.bkbg-daily-schedule-app').forEach(buildBlock); |
| 208 |
} |
| 209 |
|
| 210 |
if (document.readyState !== 'loading') { init(); } else { document.addEventListener('DOMContentLoaded', init); } |
| 211 |
})(); |
| 212 |
|