function B(t,n){t.style.cursor="pointer",t.title="Double-click to edit",t.addEventListener("dblclick",()=>{let s=!1,e=document.createElement("input");e.type="text",e.className=n.className??"nbplay-inline-edit",e.value=n.getValue(),e.style.width=Math.max(t.offsetWidth+8,48)+"px",t.replaceWith(e),e.focus(),e.select();function i(){if(s)return;s=!0;let r=n.parse(e.value.trim());r!==null&&n.apply(r),e.replaceWith(t),n.sync()}e.addEventListener("keydown",r=>{r.key==="Enter"&&(r.preventDefault(),i()),r.key==="Escape"&&(r.preventDefault(),s||(s=!0,e.replaceWith(t),n.sync()))}),e.addEventListener("blur",i)})}function H({model:t,el:n}){n.innerHTML=`
  <div class="nbplay-transport">
    <div class="nbplay-transport-controls">
      <button class="nbplay-transport-stop" title="Stop">\u25A0</button>
      <button class="nbplay-transport-play" title="Play / Pause">\u25B6</button>
    </div>
    <div class="nbplay-transport-tempo">
      <label>BPM</label>
      <input type="range" class="nbplay-transport-bpm-slider"
             min="30" max="300" step="1">
      <span class="nbplay-transport-bpm-val">120</span>
    </div>
    <div class="nbplay-transport-timesig">
      <span class="nbplay-transport-timesig-val">4/4</span>
    </div>
    <div class="nbplay-transport-position">
      <span class="nbplay-transport-bar">001</span>
      <span class="nbplay-transport-sep">:</span>
      <span class="nbplay-transport-beat">1</span>
    </div>
    <div class="nbplay-transport-loop">
      <button class="nbplay-transport-loop-btn" title="Toggle loop">\u21BB</button>
      <span class="nbplay-transport-loop-range">1 \u2013 4</span>
    </div>
  </div>`;let s=n.querySelector(".nbplay-transport-play"),e=n.querySelector(".nbplay-transport-stop"),i=n.querySelector(".nbplay-transport-bpm-slider"),r=n.querySelector(".nbplay-transport-bpm-val"),S=n.querySelector(".nbplay-transport-timesig-val"),k=n.querySelector(".nbplay-transport-bar"),w=n.querySelector(".nbplay-transport-beat"),h=n.querySelector(".nbplay-transport-loop-btn"),T=n.querySelector(".nbplay-transport-loop-range");function M(){let a=t.get("is_playing");s.textContent=a?"\u23F8":"\u25B6",s.classList.toggle("playing",a)}function g(){let a=t.get("bpm");i.value=String(a),r.textContent=Math.round(a)+" BPM"}function y(){S.textContent=t.get("time_signature_num")+"/"+t.get("time_signature_den")}function f(){k.textContent=String(t.get("bar_number")+1).padStart(3,"0"),w.textContent=String(t.get("beat_in_bar")+1)}function p(){h.classList.toggle("active",t.get("loop_enabled")),T.textContent=t.get("loop_start_bar")+1+" \u2013 "+t.get("loop_end_bar")}s.addEventListener("click",()=>{t.set("is_playing",!t.get("is_playing")),t.save_changes()}),e.addEventListener("click",()=>{t.set("is_playing",!1),t.set("bar_number",0),t.set("beat_in_bar",0),t.save_changes()}),i.addEventListener("input",()=>{let a=parseFloat(i.value);r.textContent=Math.round(a)+" BPM",t.set("bpm",a),t.save_changes()}),h.addEventListener("click",()=>{t.set("loop_enabled",!t.get("loop_enabled")),t.save_changes()}),B(r,{className:"nbplay-transport-inline-edit",getValue:()=>String(Math.round(t.get("bpm"))),parse:a=>{let o=parseInt(a,10);return isNaN(o)?null:Math.max(30,Math.min(300,o))},apply:a=>{t.set("bpm",a),t.save_changes()},sync:g}),t.on("change:is_playing",M),t.on("change:bpm",g),t.on("change:time_signature_num",y),t.on("change:time_signature_den",y),t.on("change:bar_number",f),t.on("change:beat_in_bar",f),t.on("change:loop_enabled",p),t.on("change:loop_start_bar",p),t.on("change:loop_end_bar",p);let u=null,d=0,E=0;function L(){d=performance.now(),E=t.get("bar_number")*t.get("time_signature_num")+t.get("beat_in_bar"),u=setInterval(A,50)}function v(){u!==null&&(clearInterval(u),u=null)}function A(){let a=(performance.now()-d)/1e3,o=E+Math.floor(a*t.get("bpm")/60),l=t.get("time_signature_num"),b=Math.floor(o/l),_=o%l;if(t.get("loop_enabled")){let c=t.get("loop_start_bar"),m=t.get("loop_end_bar");if(m>c&&b>=m){let C=(m-c)*l,x=(o-c*l)%C;b=c+Math.floor(x/l),_=x%l}}(b!==t.get("bar_number")||_!==t.get("beat_in_bar"))&&(t.set("bar_number",b),t.set("beat_in_bar",_),t.save_changes())}return t.on("change:is_playing",()=>{t.get("is_playing")?L():v()}),t.on("change:bpm",()=>{t.get("is_playing")&&(v(),L())}),t.set("is_playing",!1),t.set("bar_number",0),t.set("beat_in_bar",0),M(),g(),y(),f(),p(),()=>{v()}}var q={render:H};export{q as default};
//# sourceMappingURL=transport.js.map
