export function calculateThickness(copper,dielectric) { if(copper.length!==6 || dielectric.length!==5)throw new Error('Use exactly six copper layers and five dielectric intervals.'); const values=[...copper,...dielectric]; if(values.some(value=>typeof value!=='number'||!Number.isFinite(value)||value<=0||value>10000))throw new Error('Enter a positive thickness of no more than 10,000 µm for each layer.'); return Math.round(values.reduce((sum,value)=>sum+value,0))/1000; } if(typeof document!=='undefined') { const form=document.querySelector('[data-stackup-planner]'); if(form)form.addEventListener('submit',event=>{ event.preventDefault(); const output=form.querySelector('[data-total]'); try { const values=selector=>[...form.querySelectorAll(selector)].map(input=>Number(input.value)); output.textContent=calculateThickness(values('[data-copper]'),values('[data-dielectric]')).toFixed(3)+' mm nominal construction thickness'; } catch(error){output.textContent=error.message;} }); }