/* widget: volledig aanpasbare verjaardagstaart */ function mountBirthday(root, initState){ const S = Object.assign({ name:"", age:8, layers:2, cake:"#f2b880", icing:"#ff78a8", plate:"#57c7d4", decoration:"sprinkles", candles:true, }, initState || {}); root.innerHTML = `
`; const q=s=>root.querySelector(s), name=q('.bd-name'), age=q('.bd-age'), layers=q('.bd-layers'), cakeColor=q('.bd-cake-color'), icingColor=q('.bd-icing-color'), plateColor=q('.bd-plate-color'), decoration=q('.bd-decoration'), candles=q('.bd-candles'), cake=q('.bd-cake'), title=q('.bd-title'), badge=q('.bd-age-badge'); name.value=S.name; age.value=S.age; layers.value=S.layers; cakeColor.value=S.cake; icingColor.value=S.icing; plateColor.value=S.plate; decoration.value=S.decoration; candles.checked=S.candles; function sync(){ S.name=name.value.trim(); S.age=Math.max(1,Math.min(120,+age.value||1)); S.layers=+layers.value; S.cake=cakeColor.value; S.icing=icingColor.value; S.plate=plateColor.value; S.decoration=decoration.value; S.candles=candles.checked; render(); } function render(){ cake.innerHTML=""; for(let n=S.layers;n>=1;n--){ const layer=document.createElement('div'); layer.className='bd-layer bd-layer-'+n; layer.style.setProperty('--cake',S.cake); layer.style.setProperty('--icing',S.icing); if(S.decoration!=="none"){ const deco=document.createElement('div'); deco.className='bd-deco '+S.decoration; deco.textContent=S.decoration==='fruit'?'🍓 🍒 🍓':S.decoration==='stars'?'★ ✦ ★ ✦ ★':'• • • • • •'; layer.appendChild(deco); } if(n===S.layers && S.candles){ const row=document.createElement('div'); row.className='bd-candle-row'; const count=Math.min(S.age,20); for(let i=0;ie.stopPropagation()); [name,age,layers,cakeColor,icingColor,plateColor,decoration,candles].forEach(el=>el.addEventListener('input',sync)); q('.bd-party').addEventListener('click',()=>{ confetti(q('.bd-stage')); sndWin(); }); function labels(){ name.placeholder=T('birthdayName'); q('.bd-age-label').textContent=T('birthdayAge'); q('.bd-layers-label').textContent=T('birthdayLayers'); q('.bd-cake-label').textContent=T('birthdayCakeColor'); q('.bd-icing-label').textContent=T('birthdayIcing'); q('.bd-plate-label').textContent=T('birthdayPlate'); q('.bd-candles-label').textContent=T('birthdayCandles'); q('.bd-party').textContent=T('birthdayCelebrate'); const keys=['birthdaySprinkles','birthdayFruit','birthdayStars','birthdayNone']; [...decoration.options].forEach((o,i)=>o.textContent=T(keys[i])); render(); } document.addEventListener('langchange',labels); labels(); return { getState:()=>({...S}) }; }