@hyperframes/studio 0.8.225 → 0.8.227
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{hyperframes-player-Do2ZF6Lp.js → hyperframes-player-merzSkao.js} +3 -3
- package/dist/assets/{index-CK4_IJ8G.js → index-B4XEg_n-.js} +1 -1
- package/dist/assets/{index-Dxb7fTWf.js → index-DoXOJGW5.js} +174 -174
- package/dist/{chunk-2PQ3U3LU.js → chunk-CM72ZNGU.js} +12 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.html +1 -1
- package/dist/index.js +31 -27
- package/dist/player.d.ts +1 -0
- package/dist/player.js +1 -1
- package/package.json +8 -8
- package/src/components/nle/NLEPreview.test.ts +2 -1
- package/src/components/nle/NLEPreview.tsx +8 -45
- package/src/components/nle/previewStage.ts +49 -0
- package/src/player/components/Player.test.ts +33 -0
- package/src/player/components/Player.tsx +12 -5
- package/src/player/store/previewQualitySlice.test.ts +19 -1
- package/src/player/store/previewQualitySlice.ts +4 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var We=Object.defineProperty;var ze=(r,t,e)=>t in r?We(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var u=(r,t,e)=>ze(r,typeof t!="symbol"?t+"":t,e);import{S as $e,r as je,a as be,b as Ae,i as Be,c as A,d as we,p as qe,e as Ge,f as Ye,g as Xe,s as Ke,h as Se,F as Ee}from"./index-
|
|
1
|
+
var We=Object.defineProperty;var ze=(r,t,e)=>t in r?We(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var u=(r,t,e)=>ze(r,typeof t!="symbol"?t+"":t,e);import{S as $e,r as je,a as be,b as Ae,i as Be,c as A,d as we,p as qe,e as Ge,f as Ye,g as Xe,s as Ke,h as Se,F as Ee}from"./index-DoXOJGW5.js";function Ze(r){return r.hasRuntime||r.runtimeInjected?!1:!!(r.hasNestedCompositions||r.hasTimelines&&r.attempts>=5)}function F(r){return typeof r=="object"&&r!==null}function Je(r){return F(r)&&typeof r.getDuration=="function"}function Qe(r){return F(r)&&typeof r.duration=="function"&&typeof r.time=="function"&&typeof r.seek=="function"&&typeof r.play=="function"&&typeof r.pause=="function"}function et(r){if(!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(r))throw new Error(`Invalid HyperFrames runtime version: ${r}`);return`https://cdn.jsdelivr.net/npm/@hyperframes/core@${r}/dist/hyperframe.runtime.iife.js`}const B=typeof __HYPERFRAMES_RUNTIME_CDN_URL__=="string"?__HYPERFRAMES_RUNTIME_CDN_URL__:et("0.0.0-dev");function Y(r){if(r===null)return null;const t=Number.parseInt(r,10);return Number.isFinite(t)&&t>0?t:null}function tt(r){const t=(r==null?void 0:r.querySelector("[data-composition-id][data-width][data-height]"))??(r==null?void 0:r.querySelector("[data-width][data-height]"));if(!t)return null;const e=Y(t.getAttribute("data-width")),i=Y(t.getAttribute("data-height"));return e!==null&&i!==null?{width:e,height:i}:null}function it(r){return Array.isArray(r)?r.find(t=>typeof t=="string"&&t.trim()!==""&&t!=="[object Event]")??null:null}class st{constructor(t,e){u(this,"_interval",null);u(this,"_runtimeInjected",!1);u(this,"_runtimeScript",null);u(this,"_failure",null);this._iframe=t,this._callbacks=e}get failed(){return this._failure!==null&&this._failure.document===this._iframe.contentDocument}get runtimeInjected(){return this._runtimeInjected}start(){this.stop(),this._failure=null,this._runtimeInjected=!1;let t=0;this._interval=setInterval(()=>{t++;let e=null;try{e=this._poll(t)}catch(i){i instanceof DOMException&&i.name==="SecurityError"||(e={kind:"error",message:i instanceof Error?i.message:String(i)})}e??(e=this._deadlineOutcome(t)),e&&(this.stop(),e.kind==="error"?(this._failure={document:this._iframe.contentDocument},this._callbacks.onError(e.message)):this._callbacks.onReady(e.result))},200)}_deadlineOutcome(t){var e,i;return t<40||(i=(e=this._callbacks).hostOwnsDeadline)!=null&&i.call(e)?null:{kind:"error",message:"Composition timeline not found after 8s"}}_poll(t){const e=this._iframe.contentWindow;if(!e)return null;const i=it(Reflect.get(e,$e));if(i!==null)return{kind:"error",message:i};const s=this._iframe.contentDocument,n=Reflect.get(e,"__timelines"),o=this.hasRuntimeBridge(e);if(Ze({hasRuntime:o,hasTimelines:F(n)&&Object.keys(n).length>0,hasNestedCompositions:!!(s!=null&&s.querySelector("[data-composition-src]")),runtimeInjected:this._runtimeInjected,attempts:t}))return this._injectRuntime(),null;if(this._runtimeInjected&&!o)return null;const a=this._resolveReadyResult(e,s);return a?{kind:"ready",result:a}:null}_resolveReadyResult(t,e){var n;const i=this._resolvePlaybackDurationAdapter(t)??{kind:"document",getDuration:()=>0};let s=i.getDuration();if(!Number.isFinite(s)||s<=0){if(i.kind==="direct-timeline")return null;s=e?((n=je(e))==null?void 0:n.durationSeconds)??0:0}return s<=0?null:{duration:s,adapter:{...i,getDuration:()=>s},compositionSize:tt(e)}}stop(){this._runtimeScript&&(this._runtimeScript.onerror=null,this._runtimeScript=null),this.failed||(this._failure=null),this._interval!==null&&(clearInterval(this._interval),this._interval=null)}resolveDirectTimelineAdapter(){try{const t=this._iframe.contentWindow;return t?this._resolveDirectTimelineAdapterFromWindow(t):null}catch{return null}}resolveDirectTimelineAdapterFromWindow(t){return this._resolveDirectTimelineAdapterFromWindow(t)}hasRuntimeBridge(t){return F(Reflect.get(t,"__player"))}_injectRuntime(){var t,e,i,s;this._runtimeInjected=!0;try{const n=this._iframe.contentDocument;if(!n)return;const o=n.createElement("script");o.src=((e=(t=this._callbacks).resolveRuntimeUrl)==null?void 0:e.call(t))??B,this._runtimeScript=o,o.onerror=()=>{this._runtimeScript!==o||this._iframe.contentDocument!==n||(this.stop(),this._failure={document:n},this._callbacks.onError("HyperFrames runtime failed to load from "+o.src))},(n.head||n.documentElement).appendChild(o),(s=(i=this._callbacks).onRuntimeInjected)==null||s.call(i)}catch{}}_resolveDirectTimelineAdapterFromWindow(t){var a,c;if(this.hasRuntimeBridge(t))return null;const e=Reflect.get(t,"__timelines");if(!F(e))return null;const i=Object.keys(e);if(i.length===0)return null;const s=(c=(a=this._iframe.contentDocument)==null?void 0:a.querySelector("[data-composition-id]"))==null?void 0:c.getAttribute("data-composition-id"),n=s&&s in e?s:i[i.length-1],o=e[n];return Qe(o)?o:null}_resolvePlaybackDurationAdapter(t){const e=Reflect.get(t,"__player");if(Je(e))return{kind:"runtime",getDuration:()=>e.getDuration()};const i=this._resolveDirectTimelineAdapterFromWindow(t);return i?{kind:"direct-timeline",timeline:i,getDuration:()=>i.duration()}:null}}const rt=`
|
|
2
2
|
:host {
|
|
3
3
|
display: block;
|
|
4
4
|
position: relative;
|
|
@@ -474,5 +474,5 @@ var We=Object.defineProperty;var ze=(r,t,e)=>t in r?We(r,t,{enumerable:!0,config
|
|
|
474
474
|
background: var(--hfp-accent, #fff);
|
|
475
475
|
pointer-events: none;
|
|
476
476
|
}
|
|
477
|
-
`,nt='<svg width="24" height="24" viewBox="46 21 54 56" fill="currentColor"><path d="M87.5129 57.5141L56.9696 73.5433C52.8371 75.7098 48.7046 73.2553 49.6688 69.2104L58.9483 30.1391C59.9125 26.0942 65.2097 23.6397 68.3154 25.8062L91.2447 41.8354C96.4668 45.4796 94.4631 53.8699 87.5129 57.5141Z"/></svg>',ot='<svg width="24" height="24" viewBox="0 0 18 18" fill="currentColor"><rect x="3" y="2" width="4" height="14"/><rect x="11" y="2" width="4" height="14"/></svg>',Te='<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3z"/><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z"/><path d="M14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/></svg>',Re='<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3z"/><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z"/></svg>',at='<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3z"/><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z" opacity="0.3"/><line x1="18" y1="7" x2="14" y2="17" stroke="currentColor" stroke-width="2"/></svg>',dt=[.25,.5,1,1.5,2,4];function k(r){return Number.isInteger(r)?`${r}x`:`${r}x`}function Ce(r){if(!Number.isFinite(r)||r<0)return"0:00";const t=Math.floor(r),e=Math.floor(t/60),i=t%60;return`${e}:${i.toString().padStart(2,"0")}`}function ut(r,t,e={}){const i=e.speedPresets??dt,s=document.createElement("div");s.className="hfp-controls",s.addEventListener("click",d=>{d.stopPropagation()});const n=document.createElement("button");n.className="hfp-play-btn",n.type="button",n.innerHTML=`<span class="hfp-ico hfp-ico-play">${nt}</span><span class="hfp-ico hfp-ico-pause">${ot}</span>`,n.setAttribute("aria-label","Play");const o=document.createElement("div");o.className="hfp-scrubber";const a=document.createElement("div");a.className="hfp-progress",a.style.width="0%",o.appendChild(a);const c=document.createElement("span");c.className="hfp-time",c.textContent="0:00 / 0:00";const p=document.createElement("div");p.className="hfp-speed-wrap";const l=document.createElement("button");l.className="hfp-speed-btn",l.type="button",l.textContent="1x",l.setAttribute("aria-label","Playback speed: 1x");const g=document.createElement("div");g.className="hfp-speed-menu",g.setAttribute("role","menu");for(const d of i){const h=document.createElement("button");h.className="hfp-speed-option",h.type="button",h.setAttribute("role","menuitem"),h.dataset.speed=String(d),h.textContent=k(d),d===1&&h.classList.add("hfp-active"),g.appendChild(h)}p.appendChild(g),p.appendChild(l);const _=document.createElement("div");_.className="hfp-volume-wrap";const m=document.createElement("button");m.className="hfp-mute-btn",m.type="button",m.innerHTML=Te,m.setAttribute("aria-label","Mute");const y=document.createElement("div");y.className="hfp-volume-slider-wrap";const f=document.createElement("div");f.className="hfp-volume-slider",f.setAttribute("role","slider"),f.setAttribute("aria-label","Volume"),f.setAttribute("aria-valuemin","0"),f.setAttribute("aria-valuemax","100"),f.setAttribute("aria-valuenow","100"),f.tabIndex=0;const b=document.createElement("div");b.className="hfp-volume-fill",b.style.width="100%",f.appendChild(b),y.appendChild(f),_.appendChild(y),_.appendChild(m),e.audioLocked&&(_.style.display="none"),s.appendChild(n),s.appendChild(o),s.appendChild(c),s.appendChild(_),s.appendChild(p),r.appendChild(s);let P=!1,w=!1,T=1,R=null;i.indexOf(1);const U=(d,h)=>d?at:h===0||h<.5?Re:Te;n.addEventListener("click",d=>{d.stopPropagation(),P?t.onPause():t.onPlay()}),m.addEventListener("click",d=>{d.stopPropagation(),t.onMuteToggle()});let C=!1;const V=d=>{const h=f.getBoundingClientRect(),v=Math.max(0,Math.min(1,(d-h.left)/h.width));T=v,b.style.width=`${v*100}%`,f.setAttribute("aria-valuenow",String(Math.round(v*100))),w&&v>0&&t.onMuteToggle(),m.innerHTML=U(w,v),t.onVolumeChange(v)};f.addEventListener("mousedown",d=>{d.stopPropagation(),C=!0,V(d.clientX)});const oe=d=>{C&&V(d.clientX)},ae=()=>{C=!1};document.addEventListener("mousemove",oe),document.addEventListener("mouseup",ae),f.addEventListener("touchstart",d=>{C=!0;const h=d.touches[0];h&&V(h.clientX)},{passive:!0});const de=d=>{if(C){const h=d.touches[0];h&&V(h.clientX)}},ue=()=>{C=!1};document.addEventListener("touchmove",de,{passive:!0}),document.addEventListener("touchend",ue);const le=.05;f.addEventListener("keydown",d=>{let h=T;if(d.key==="ArrowRight"||d.key==="ArrowUp")h=Math.min(1,T+le);else if(d.key==="ArrowLeft"||d.key==="ArrowDown")h=Math.max(0,T-le);else return;d.preventDefault(),d.stopPropagation(),T=h,b.style.width=`${h*100}%`,f.setAttribute("aria-valuenow",String(Math.round(h*100))),w&&h>0&&t.onMuteToggle(),m.innerHTML=U(w,h),t.onVolumeChange(h)});const he=d=>{for(const h of g.querySelectorAll(".hfp-speed-option"))h.classList.toggle("hfp-active",h.dataset.speed===String(d))};l.addEventListener("click",d=>{d.stopPropagation();const h=g.classList.toggle("hfp-open");l.setAttribute("aria-expanded",String(h))}),g.addEventListener("click",d=>{d.stopPropagation();const h=d.target.closest(".hfp-speed-option");if(!h)return;const v=parseFloat(h.dataset.speed);i.indexOf(v),l.textContent=k(v),l.setAttribute("aria-label",`Playback speed: ${k(v)}`),he(v),g.classList.remove("hfp-open"),l.setAttribute("aria-expanded","false"),t.onSpeedChange(v)});const ce=()=>{g.classList.remove("hfp-open"),l.setAttribute("aria-expanded","false")};document.addEventListener("click",ce);const H=d=>{const h=o.getBoundingClientRect(),v=Math.max(0,Math.min(1,(d-h.left)/h.width));t.onSeek(v)};let S=!1;o.addEventListener("mousedown",d=>{var h;d.stopPropagation(),S=!0,(h=t.onScrubStart)==null||h.call(t),H(d.clientX)});const pe=d=>{S&&H(d.clientX)},me=()=>{var d;S&&(S=!1,(d=t.onScrubEnd)==null||d.call(t))};document.addEventListener("mousemove",pe),document.addEventListener("mouseup",me),o.addEventListener("touchstart",d=>{var v;S=!0,(v=t.onScrubStart)==null||v.call(t);const h=d.touches[0];h&&H(h.clientX)},{passive:!0});const fe=d=>{if(S){const h=d.touches[0];h&&H(h.clientX)}},_e=()=>{var d;S&&(S=!1,(d=t.onScrubEnd)==null||d.call(t))};document.addEventListener("touchmove",fe,{passive:!0}),document.addEventListener("touchend",_e);const ge=()=>P&&!S&&!C&&!s.querySelector(":focus-visible"),ye=()=>{s.classList.remove("hfp-hidden"),R&&clearTimeout(R),R=setTimeout(()=>{ge()&&s.classList.add("hfp-hidden")},3e3)},E=r instanceof ShadowRoot?r.host:r,L=()=>ye(),ve=()=>{ge()&&s.classList.add("hfp-hidden")};return E.addEventListener("mousemove",L),E.addEventListener("keydown",L),E.addEventListener("focusin",L),E.addEventListener("mouseleave",ve),{updateTime(d,h){const v=h>0?Math.min(d,h):d,He=h>0?v/h*100:0;a.style.width=`${He}%`,c.textContent=`${Ce(v)} / ${Ce(h)}`},updatePlaying(d){const h=d!==P;P=d,n.classList.toggle("hfp-playing",d),n.setAttribute("aria-label",d?"Pause":"Play"),d?h&&ye():(R&&clearTimeout(R),s.classList.remove("hfp-hidden"))},updateSpeed(d){i.indexOf(d),l.textContent=k(d),l.setAttribute("aria-label",`Playback speed: ${k(d)}`),he(d)},updateMuted(d){w=d,m.innerHTML=U(d,T),m.setAttribute("aria-label",d?"Unmute":"Mute")},updateVolume(d){T=d,b.style.width=`${d*100}%`,f.setAttribute("aria-valuenow",String(Math.round(d*100))),m.innerHTML=U(w,d)},setVolumeControlsHidden(d){_.style.display=d?"none":""},show(){s.style.display=""},hide(){s.style.display="none"},destroy(){document.removeEventListener("mousemove",pe),document.removeEventListener("mouseup",me),document.removeEventListener("touchmove",fe),document.removeEventListener("touchend",_e),document.removeEventListener("mousemove",oe),document.removeEventListener("mouseup",ae),document.removeEventListener("touchmove",de),document.removeEventListener("touchend",ue),document.removeEventListener("click",ce),E.removeEventListener("mousemove",L),E.removeEventListener("keydown",L),E.removeEventListener("focusin",L),E.removeEventListener("mouseleave",ve),R&&clearTimeout(R),s.remove()}}}function lt(r,t,e,i,s,n=!1){const o=i?i.split(",").map(Number).filter(p=>!isNaN(p)&&p>0):void 0,a={...o?{speedPresets:o}:{},audioLocked:n},c=ut(r,s,a);return c.updateMuted(t),c.updateVolume(e),c}function Pe(r,t,e){return t?(e||(e=document.createElement("img"),e.className="hfp-poster",r.appendChild(e)),e.src=t,e):(e==null||e.remove(),null)}function ht(r){return r.composedPath().some(t=>t instanceof HTMLElement&&t.classList.contains("hfp-controls"))}let W=null;function ct(r,t){if(typeof CSSStyleSheet<"u")try{W||(W=new CSSStyleSheet,W.replaceSync(t)),r.adoptedStyleSheets=[W];return}catch{}const e=document.createElement("style");e.textContent=t,r.appendChild(e)}function pt(){const r=document.createElement("div");r.className="hfp-container";const t=document.createElement("iframe");return t.className="hfp-iframe",t.sandbox.add("allow-scripts","allow-same-origin"),t.allow="autoplay; fullscreen",t.referrerPolicy="no-referrer",t.title="HyperFrames Composition",r.appendChild(t),{container:r,iframe:t}}function mt(r,t,e,i){const s=r.offsetWidth,n=r.offsetHeight;if(s===0||n===0)return!1;const o=Math.min(s/e,n/i);return t.style.width=`${e}px`,t.style.height=`${i}px`,t.style.transform=`translate(-50%, -50%) scale(${o})`,!0}const ft=100,_t=.001;function gt(r,t,e){if(e.end<=0)return!1;const i=e.shown<e.end&&t>0?t+_t:0;return r+i>=e.end}class yt{constructor(t){u(this,"_raf",null);u(this,"_lastUpdateMs",0);u(this,"_tick",null);this._callbacks=t}start(t,e,i,s,n){this.stop();let o=null,a=0,c=0;const p=()=>{if(s()){this._raf=null;return}let l;try{l=t.time()}catch{this._raf=null;return}const g=i(),_=n();_.end>0&&(l=Math.min(l,_.end));const m=o===null?0:l-o;m!==0&&(c=Math.min(m,a),a=m),o=l;const y=gt(l,c,_);y&&(l=_.shown);const f=performance.now();if((f-this._lastUpdateMs>ft||y)&&(this._lastUpdateMs=f,this._callbacks.onTimeUpdate(l,g)),y){if(this._callbacks.getLoop()){this._callbacks.restart();return}try{t.pause(),_.shown<_.end&&t.seek(_.shown,!1)}catch{}this._callbacks.onPaused(),this._raf=null;return}this._raf=requestAnimationFrame(p)};this._tick=p,this._raf=requestAnimationFrame(p)}poll(){this._raf===null||!this._tick||(cancelAnimationFrame(this._raf),this._tick())}stop(){this._raf!==null&&(cancelAnimationFrame(this._raf),this._raf=null)}get isRunning(){return this._raf!==null}}function vt(r){const t=Array.from(r.querySelectorAll("[data-composition-id]"));if(t.length===0)return r.body?[r.body]:[];const e=[];for(const i of t)At(i)||e.push(i);return bt(r),e}function bt(r){const t=r.body;if(!t||typeof console>"u"||typeof console.warn!="function")return;const e=t.querySelectorAll("audio[data-start], video[data-start]");if(e.length===0)return;const i=[];for(const s of e)s.closest("[data-composition-id]")||i.push(s);i.length!==0&&console.warn(`[hyperframes-player] selectMediaObserverTargets: composition hosts are present, but ${i.length} body-level timed media element(s) sit outside every [data-composition-id] subtree and will not be observed. Move them inside a composition host or the parent-frame proxy will never adopt them.`,i)}function At(r){let t=r.parentElement;for(;t;){if(t.hasAttribute("data-composition-id"))return!0;t=t.parentElement}return!1}const wt=1e-5;function Fe(r){return r+wt}function St(){const{userAgent:r,maxTouchPoints:t}=navigator;return/iP(hone|ad|od)/.test(r)||/Macintosh/.test(r)&&t>1}const X=.04,Et=.5,Tt=.03,Rt=[[.3,.25],[.1,.1]],Ct=.01,Pt=.1,Lt=.1,O=new WeakMap,q=new WeakSet;function Dt(r,t,e,i,s=r.tagName==="AUDIO"){var g;const n=Math.abs(t);i&&n<=X&&q.delete(r);const o=!q.has(r)||n>Et;if(s&&i&&n>Lt&&o)return O.delete(r),q.add(r),{rate:e,seek:!0};const a=Math.sign(t),c=O.get(r);if(n>X)O.set(r,a);else if(c!==a||n<=Ct)return O.delete(r),{rate:e,seek:!1};const p=((g=Rt.find(([_])=>n>_))==null?void 0:g[1])??Tt,l=s?Math.min(p,Pt):p;return{rate:e*(1+a*l),seek:!1}}function kt(r){O.delete(r),q.delete(r)}const Mt=.004,xt=1.5;class It{constructor(t){u(this,"_entries",[]);u(this,"_mediaObserver");u(this,"_playbackErrorPosted",!1);u(this,"_audioOwner","runtime");u(this,"_urlAudioEntry",null);u(this,"_urlAudioSrc",null);u(this,"_dispatchEvent");u(this,"_getMuted");u(this,"_getVolume");u(this,"_getPlaybackRate");u(this,"_getCurrentTime");u(this,"_isPaused");this._dispatchEvent=t.dispatchEvent,this._getMuted=t.getMuted,this._getVolume=t.getVolume,this._getPlaybackRate=t.getPlaybackRate,this._getCurrentTime=t.getCurrentTime,this._isPaused=t.isPaused}get audioOwner(){return this._audioOwner}get entries(){return this._entries}resetForIframeLoad(){this._playbackErrorPosted=!1;const t=this._audioOwner==="parent";this._audioOwner="runtime",this.pauseAll();for(const e of this._entries)e!==this._urlAudioEntry&&(e.el.src="");this._entries=this._urlAudioEntry?[this._urlAudioEntry]:[],this._urlAudioSrc&&!this._urlAudioEntry&&(this._urlAudioEntry=this._createEntry(this._urlAudioSrc,"audio",0,1/0)),this.teardownObserver(),t&&this._dispatchEvent(new CustomEvent("audioownershipchange",{detail:{owner:"runtime",reason:"iframe-reload"}}))}destroy(){this.teardownObserver();for(const t of this._entries)t.el.pause(),t.el.src="";this._entries=[],this._urlAudioEntry=null,this._urlAudioSrc=null,this._audioOwner="runtime",this._playbackErrorPosted=!1}updateMuted(t){for(const e of this._entries)e.el.muted=t}updateVolume(t){for(const e of this._entries)e.el.volume=t}updatePlaybackRate(t){for(const e of this._entries)e.el.playbackRate=t}_playEntry(t){t.el.src&&t.el.play().catch(e=>this._reportPlaybackError(e))}_playEntryIfActive(t){this._refreshEntryBounds(t),this._inWindow(t,this._getCurrentTime())&&this._playEntry(t)}_refreshEntryBounds(t){var i;if(!((i=t.source)!=null&&i.isConnected))return;const e=be(t.source);t.start=e.start??0,t.mediaStart=Ae(t.source).mediaStart,t.duration=e.duration!=null&&e.duration>0?e.duration:Number.POSITIVE_INFINITY}_inWindow(t,e){return Be(e,t.start,t.start+t.duration)}_preseekUpcoming(t,e){const i=t.start-e;i<=0||i>xt||!t.el.paused||Math.abs(t.el.currentTime-t.mediaStart)>X&&this._seekTo(t,t.mediaStart)}_seekTo(t,e,i=!1){const s=i?(t.seekLatency??0)*this._getPlaybackRate():0;t.seekIssuedAt=i?performance.now():void 0,t.el.currentTime=Fe(e+s)}_noteSeekLanded(t){if(t.seekIssuedAt===void 0)return;const e=(performance.now()-t.seekIssuedAt)/1e3;t.seekLatency=t.seekLatency===void 0?e:(t.seekLatency+e)/2,t.seekIssuedAt=void 0}_releaseSteering(t){kt(t.el),t.lastOffset=void 0;const e=this._getPlaybackRate();t.el.playbackRate!==e&&(t.el.playbackRate=e)}_mediaTime(t,e){return e-t.start+t.mediaStart}_gateEntryPlayback(t,e){return this._inWindow(t,e)?(this._audioOwner==="parent"&&!this._isPaused()&&t.el.paused&&this._playEntry(t),!0):(t.el.paused||t.el.pause(),this._releaseSteering(t),!1)}playAll(){for(const t of this._entries)this._playEntryIfActive(t)}primeAll(){if(St())for(const t of this._entries)t.el.paused&&(t.el.play().catch(()=>{}),t.el.pause())}pauseAll(){for(const t of this._entries)t.el.pause()}stopAdoptedMedia(){for(const t of this._entries)t.source&&t.el.pause()}seekAll(t){for(const e of this._entries)this._refreshEntryBounds(e),this._inWindow(e,t)&&this._jumpTo(e,this._mediaTime(e,t))}scrubAll(t){for(const e of this._entries)this._refreshEntryBounds(e),this._inWindow(e,t)?(this._jumpTo(e,this._mediaTime(e,t)),this._playEntry(e)):e.el.paused||e.el.pause()}mirrorTime(t,e){const i=(e==null?void 0:e.force)===!0;for(const s of this._entries){this._refreshEntryBounds(s),this._preseekUpcoming(s,t);const n=s.el.paused;if(!this._gateEntryPlayback(s,t))continue;const o=this._mediaTime(s,t),a=o-s.el.currentTime;if(i||n){Math.abs(a)>X&&this._jumpTo(s,o);continue}this._steer(s,o,a)}}_steer(t,e,i){const s=t.lastOffset!==void 0&&Math.abs(i-t.lastOffset)<Mt;t.lastOffset=i;const{rate:n,seek:o}=Dt(t.el,i,this._getPlaybackRate(),s,!0);o?this._jumpTo(t,e,!0):Math.abs(t.el.playbackRate-n)>1e-6&&(t.el.playbackRate=n)}_jumpTo(t,e,i=!1){this._seekTo(t,e,i),this._releaseSteering(t)}promoteToParentProxy(t,e){if(this._audioOwner==="parent")return;if(this._audioOwner="parent",t)for(const s of t.querySelectorAll("video, audio"))A(s)&&(s.muted=!0);for(const s of[...this._entries])this._repointToSource(s);const i=this._getCurrentTime();e?e(i,{force:!0}):this.mirrorTime(i,{force:!0}),this._isPaused()||this.playAll(),this._dispatchEvent(new CustomEvent("audioownershipchange",{detail:{owner:"parent",reason:"autoplay-blocked"}}))}setupFromIframe(t){const e=t.querySelectorAll("audio[data-start], video[data-start]");for(const i of e)A(i)&&this._adoptIframeMedia(i);this._observeDynamicMedia(t)}setupFromUrl(t){if(this._urlAudioSrc===t&&this._urlAudioEntry)return;this.teardownUrlAudio();const e=this._createEntry(t,"audio",0,1/0);this._urlAudioEntry=e,this._urlAudioSrc=t,e&&this._audioOwner==="parent"&&!this._isPaused()&&(this.mirrorTime(this._getCurrentTime(),{force:!0}),this.playAll())}teardownUrlAudio(){const t=this._urlAudioEntry;if(this._urlAudioEntry=null,this._urlAudioSrc=null,!t)return;t.el.pause(),t.el.src="";const e=this._entries.indexOf(t);e!==-1&&this._entries.splice(e,1)}teardownObserver(){var t;(t=this._mediaObserver)==null||t.disconnect(),this._mediaObserver=void 0}_reportPlaybackError(t){this._playbackErrorPosted||(this._playbackErrorPosted=!0,this._dispatchEvent(new CustomEvent("playbackerror",{detail:{source:"parent-proxy",error:t}})))}_createEntry(t,e,i,s,n){if(!n&&this._urlTaken(t))return null;const o=e==="video"?document.createElement("video"):new Audio;o.preload="auto";const a=n==null?void 0:n.getAttribute("crossorigin");a!=null&&o.setAttribute("crossorigin",a),o.src=t,o.load(),o.muted=this._getMuted(),o.volume=this._getVolume();const c=this._getPlaybackRate();c!==1&&(o.playbackRate=c);const p={el:o,start:i,duration:s,mediaStart:n?Ae(n).mediaStart:0,source:n};return o.addEventListener("seeked",()=>this._noteSeekLanded(p)),this._entries.push(p),p}_resolveIframeMediaSrc(t){var i;const e=t.getAttribute("src")||((i=t.querySelector("source"))==null?void 0:i.getAttribute("src"));return e?new URL(e,t.ownerDocument.baseURI).href:null}_adoptIframeMedia(t){if(t.preload==="metadata"||t.preload==="none"||this._entries.some(c=>c.source===t)||t.tagName==="VIDEO"&&t.hasAttribute("muted"))return;const e=this._resolveIframeMediaSrc(t);if(!e)return;const i=be(t),s=i.start??0,n=i.duration??Number.POSITIVE_INFINITY,o=t.tagName==="VIDEO"?"video":"audio",a=this._createEntry(e,o,s,n,t);a&&this._audioOwner==="parent"&&(this.mirrorTime(this._getCurrentTime(),{force:!0}),this._isPaused()||this._playEntryIfActive(a))}_followIframeMediaSrc(t){const e=this._entries.find(i=>i.source===t);if(!e)return this._adoptIframeMedia(t);this._audioOwner!=="parent"||!this._repointToSource(e)||(this.mirrorTime(this._getCurrentTime(),{force:!0}),this._isPaused()||this._playEntryIfActive(e))}_urlTaken(t){return this._entries.some(e=>e.source&&!e.source.isConnected?!1:(e.source&&this._resolveIframeMediaSrc(e.source)||e.el.src)===t)}_repointToSource(t){const e=t.source?this._resolveIframeMediaSrc(t.source):null;return!e||t.el.src===e?!1:(t.el.src=e,t.el.load(),!0)}_detachIframeMedia(t){const e=this._entries.find(i=>i.source===t);e&&this._removeEntry(e)}_removeEntry(t){t.el.pause(),t.el.src="",this._entries.splice(this._entries.indexOf(t),1)}_observeDynamicMedia(t){if(this.teardownObserver(),typeof MutationObserver>"u"||!t.body)return;const e=new MutationObserver(n=>{for(const o of n){if(o.type==="attributes"&&o.attributeName==="src"){const a=o.target;A(a)&&a.matches("audio[data-start], video[data-start]")&&this._followIframeMediaSrc(a);continue}if(o.type==="attributes"&&o.attributeName==="preload"){const a=o.target;A(a)&&a.matches("audio[data-start], video[data-start]")&&(a.preload==="auto"?this._adoptIframeMedia(a):this._detachIframeMedia(a));continue}for(const a of o.addedNodes){if(!we(a))continue;const c=[];A(a)&&a.matches("audio[data-start], video[data-start]")&&c.push(a);const p=a.querySelectorAll("audio[data-start], video[data-start]");for(const l of p)A(l)&&c.push(l);for(const l of c)this._adoptIframeMedia(l)}for(const a of o.removedNodes){if(!we(a))continue;const c=[];A(a)&&a.matches("audio[data-start], video[data-start]")&&c.push(a);const p=a.querySelectorAll("audio[data-start], video[data-start]");for(const l of p)A(l)&&c.push(l);for(const l of c)this._detachIframeMedia(l)}}}),i={childList:!0,subtree:!0,attributes:!0,attributeFilter:["preload","src"]},s=vt(t);for(const n of s)e.observe(n,i);this._mediaObserver=e}}function Le(r,t,e){if(r===null&&t===null)return{range:null,clamped:!1};const i=r??0,s=t!==null&&e>0&&t>e,n=s?e:t,o=n??(e>0?e:1/0);return!(i>=0)||!(o>i)?{range:null,clamped:!0}:{range:{start:i,end:n},clamped:s}}function re(r,t,e){const i=r.end??t;return i<t?qe(r.start,i,e):i}function De(r,t,e,i){return r<t.start||r>=re(t,e,i)}const Ot=100;function Nt(r,t){return typeof r.currentTime=="number"&&Number.isFinite(r.currentTime)?r.currentTime:(r.frame??0)/t}function Ue(r,t,e){return e<=0?!1:r.ended===!0?!0:r.ended===!1&&!r.isPlaying?!1:t>=e}function Ft(r,t,e,i,s,n){const{duration:o}=e;if(!s){const a=Ue(r,t,o);return{start:0,shownAtEnd:o,atEnd:a,stopRuntime:!1,entering:!1}}if(r.ownsRange){const a=i&&r.ended===!0&&!r.isPlaying;return{start:s.start,shownAtEnd:t,atEnd:a,stopRuntime:!1,entering:!1}}return Ut(r,t,e,i,s,n)}function Ut(r,t,e,i,s,n){const o=s.end??e.duration,a=e.enteringRange===!0&&(t<s.start||t>=o);return{start:s.start,shownAtEnd:re(s,e.duration,n),atEnd:i&&!a&&Ue(r,t,o),stopRuntime:r.isPlaying,entering:a}}function Vt(r,t,e,i){var w;const s=Nt(r,t),n=!e.paused,o=n||r.isPlaying,a=(w=i.getPlayRange)==null?void 0:w.call(i),c=Ft(r,s,e,o,a,t),{atEnd:p,start:l}=c,g=e.duration>0?Math.min(s,e.duration):s,_=p?c.shownAtEnd:g,m=!r.isPlaying,y=p&&o;if(y&&i.getLoop())return i.media.audioOwner==="parent"&&i.media.pauseAll(),i.seek(l),i.play(),{...e,currentTime:l,paused:!1,enteringRange:!0};const f={...e,currentTime:_,paused:m,enteringRange:c.entering};i.media.audioOwner==="parent"&&(n&&m?i.media.pauseAll():!n&&!m&&i.media.playAll(),i.media.mirrorTime(_));const b=performance.now(),P=m!==e.paused;return(b-e.lastUpdateMs>Ot||P)&&(f.lastUpdateMs=b,i.updateControlsTime(_,e.duration),i.updateControlsPlaying(!m),i.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:_}}))),y&&(c.stopRuntime&&i.seek(_),i.media.audioOwner==="parent"&&i.media.pauseAll(),f.paused=!0,i.updateControlsPlaying(!1),i.dispatchEvent(new Event("ended"))),f}function Ht(r){return Array.isArray(r)?r.filter(t=>typeof t=="object"&&t!==null&&typeof t.id=="string"&&typeof t.start=="number"&&typeof t.duration=="number"):[]}function Wt(r,t,e){var o,a,c,p,l,g,_;if(r.source!==t)return;const i=r.data;if(!i||i.source!=="hf-preview")return;const s=Ge(i);if(s.status==="unsupported"){e.dispatchEvent(new CustomEvent("runtimeprotocolerror",{detail:{code:s.code,receivedVersion:s.receivedVersion}}));return}(o=e.setRuntimeFps)==null||o.call(e,s.fps);const n=s.status==="supported"&&s.metadata.capabilities.includes("play-range");if((a=e.setRuntimeOwnsPlayRange)==null||a.call(e,n),i.type==="shader-transition-state"){const m=i.state&&typeof i.state=="object"?i.state:{};e.shaderLoader.update(m,e.getShaderLoadingMode()),e.dispatchEvent(new CustomEvent("shadertransitionstate",{detail:{compositionId:i.compositionId,state:m}}));return}if(i.type==="ready"){e.onRuntimeReady();return}if(i.type==="assets-ready"){(c=e.onRuntimeAssetsReady)==null||c.call(e,i.timedOut===!0);return}if(i.type==="runtime-data-error"){(p=e.onRuntimeDataError)==null||p.call(e,i.channel,i.requestId,i.message);return}if(i.type==="runtime-data-applied"){(l=e.onRuntimeDataApplied)==null||l.call(e,i.channel,i.requestId);return}if(i.type==="state"){e.setPlaybackState(Vt({frame:i.frame??0,currentTime:i.currentTime,ended:typeof i.ended=="boolean"?i.ended:void 0,isPlaying:!!i.isPlaying,ownsRange:n},s.fps,e.getPlaybackState(),e)),(g=e.setBuffering)==null||g.call(e,i.buffering===!0);return}if(i.type==="media-autoplay-blocked"){if(((_=e.shouldPromoteMediaAutoplayFallback)==null?void 0:_.call(e))===!1)return;let m=null;try{m=e.getIframeDoc()}catch{}e.media.promoteToParentProxy(m,(y,f)=>e.media.mirrorTime(y,f)),e.sendControl("set-media-output-muted",{muted:!0});return}if(i.type==="timeline"&&i.durationInFrames>0){const m=Number(i.durationSeconds),y=Number(i.durationInFrames),f=Number.isFinite(m)&&m>0?m:y/s.fps;if(Number.isFinite(i.compositionWidth)&&i.compositionWidth>0&&Number.isFinite(i.compositionHeight)&&i.compositionHeight>0&&e.setCompositionSize(i.compositionWidth,i.compositionHeight),Number.isFinite(f)&&f>0){const b=e.getPlaybackState();e.setPlaybackState({...b,duration:f}),e.updateControlsTime(b.currentTime,f),e.onRuntimeTimelineReady(f,typeof i.assetsReady=="boolean"?i.assetsReady:void 0)}e.setScenes(Ht(i.scenes));return}i.type==="stage-size"&&Number.isFinite(i.width)&&i.width>0&&Number.isFinite(i.height)&&i.height>0&&e.setCompositionSize(i.width,i.height)}function zt(r,t){return r.includes(t)?!0:/hyperframe\.runtime\.iife\.js|__hyperframes\s*=/.test(r)}const $t=new Set([">"," "," ",`
|
|
478
|
-
`,"\r","\f"]);function Z(r,t){const e=r.toLowerCase(),i=`<${t}`;let s=0;for(;s<e.length;){const n=e.indexOf(i,s);if(n<0)return null;const o=e[n+i.length];if($t.has(o)){const a=e.indexOf(">",n+i.length);return a<0?null:{index:n,end:a+1}}s=n+i.length}return null}function jt(r,t){if(!r||zt(r,t))return r;const e=`<script src="${t}"><\/script>`,i=Z(r,"head");if(i)return r.slice(0,i.end)+e+r.slice(i.end);const s=Z(r,"body");if(s)return r.slice(0,s.index)+e+r.slice(s.index);const n=Z(r,"html");return n?r.slice(0,n.end)+e+r.slice(n.end):e+r}const D="shader-capture-scale",N="shader-loading",se="runtime-src",ke="__hf_shader_capture_scale",Me="__hf_shader_loading",G=["Preparing scene transitions","Sampling outgoing scene motion","Sampling incoming scene motion","Caching transition frames","Finalizing transition preview"];function ne(r){if(r===null)return null;const t=Number(r);return!Number.isFinite(t)||t<=0?null:String(Math.min(1,Math.max(.25,t)))}function Bt(r){if(r===null||r.trim()==="")return"composition";const t=r.trim().toLowerCase();return t==="none"||t==="false"||t==="0"||t==="off"?"none":t==="player"||t==="true"||t==="1"||t==="on"?"player":"composition"}function xe(r,t){return r.filter(e=>e!==""&&e.split("=")[0]!==t)}function qt(r,t,e){const i=r.indexOf("#"),s=i>=0?r.slice(0,i):r,n=i>=0?r.slice(i):"",o=s.indexOf("?"),a=o>=0?s.slice(0,o):s,c=o>=0?s.slice(o+1):"";let p=xe(c.split("&"),ke);p=xe(p,Me),t!==null&&p.push(`${ke}=${encodeURIComponent(t)}`),e!=="composition"&&p.push(`${Me}=${encodeURIComponent(e)}`);const l=p.join("&");return`${a}${l?`?${l}`:""}${n}`}function Gt(r,t,e){if(t===null&&e==="composition")return r;const i=[];t!==null&&i.push(`window.__HF_SHADER_CAPTURE_SCALE=${JSON.stringify(t)};`),e!=="composition"&&i.push(`window.__HF_SHADER_LOADING=${JSON.stringify(e)};`);const s=`<script data-hyperframes-player-shader-options>${i.join("")}<\/script>`;return/<head\b[^>]*>/i.test(r)?r.replace(/<head\b[^>]*>/i,n=>`${n}${s}`):/<html\b[^>]*>/i.test(r)?r.replace(/<html\b[^>]*>/i,n=>`${n}${s}`):`${s}${r}`}function K(r){return Bt(r.getAttribute(N))}function Yt(r){return Number(ne(r.getAttribute(D))??"1")}function Xt(r,t){return qt(t,ne(r.getAttribute(D)),K(r))}function z(r,t){return jt(Gt(t,ne(r.getAttribute(D)),K(r)),Ve(r))}function Ve(r){var e;const t=(e=r.getAttribute(se))==null?void 0:e.trim();if(!t)return B;try{const i=new URL(t,document.baseURI),s=i.protocol==="http:"||i.protocol==="https:",n=i.hostname==="127.0.0.1"||i.hostname==="localhost"||i.hostname==="[::1]";return s&&(n||i.origin===location.origin)?i.href:B}catch{return B}}function Kt(){const r=document.createElement("div");r.className="hfp-shader-loader",r.setAttribute("role","status"),r.setAttribute("aria-live","polite"),r.setAttribute("aria-label","Preparing scene transitions"),r.setAttribute("data-hyperframes-ignore",""),r.draggable=!1;const t=m=>{m.preventDefault(),m.stopPropagation()};for(const m of["selectstart","dragstart","pointerdown","mousedown","click","dblclick","contextmenu","touchstart"])r.addEventListener(m,t,{capture:!0});const e=document.createElement("div");e.className="hfp-shader-loader-panel",e.draggable=!1;const i=document.createElement("div");i.className="hfp-shader-loader-mark",i.draggable=!1,i.innerHTML=['<svg width="78" height="78" viewBox="0 0 100 100" fill="none" aria-hidden="true" draggable="false">','<path d="M10.1851 57.8021L33.1145 73.8313C36.2202 75.9978 41.5173 73.5433 42.4816 69.4984L51.7611 30.4271C52.7253 26.3822 48.5802 23.9277 44.4602 26.0942L13.917 42.1235C6.96677 45.7676 4.97564 54.1579 10.1851 57.8021Z" fill="url(#hfp-shader-loader-grad-left)"/>','<path d="M87.5129 57.5141L56.9696 73.5433C52.8371 75.7098 48.7046 73.2553 49.6688 69.2104L58.9483 30.1391C59.9125 26.0942 65.2097 23.6397 68.3154 25.8062L91.2447 41.8354C96.4668 45.4796 94.4631 53.8699 87.5129 57.5141Z" fill="url(#hfp-shader-loader-grad-right)"/>',"<defs>",'<linearGradient id="hfp-shader-loader-grad-left" x1="48.5676" y1="25" x2="44.7804" y2="71.9384" gradientUnits="userSpaceOnUse">','<stop stop-color="#06E3FA"/>','<stop offset="1" stop-color="#4FDB5E"/>',"</linearGradient>",'<linearGradient id="hfp-shader-loader-grad-right" x1="54.8282" y1="73.8392" x2="72.0989" y2="32.8932" gradientUnits="userSpaceOnUse">','<stop stop-color="#06E3FA"/>','<stop offset="1" stop-color="#4FDB5E"/>',"</linearGradient>","</defs>","</svg>"].join("");const s=document.createElement("div");s.className="hfp-shader-loader-title";const n=document.createElement("span");n.className="hfp-shader-loader-title-text",n.textContent=G[0],s.appendChild(n);const o=document.createElement("div");o.className="hfp-shader-loader-detail",o.textContent="Rendering animated scene samples for shader transitions.";const a=document.createElement("div");a.className="hfp-shader-loader-track",a.setAttribute("aria-hidden","true");const c=document.createElement("div");c.className="hfp-shader-loader-fill",a.appendChild(c);const p=document.createElement("div");p.className="hfp-shader-loader-progress";const l=m=>{const y=document.createElement("div");y.className="hfp-shader-loader-row";const f=document.createElement("span");f.className="hfp-shader-loader-label",f.textContent=m;const b=document.createElement("span");return b.className="hfp-shader-loader-value",y.appendChild(f),y.appendChild(b),p.appendChild(y),{row:y,label:f,value:b}},g=l("transition"),_=l("transition frame");return e.appendChild(i),e.appendChild(s),e.appendChild(o),e.appendChild(a),e.appendChild(p),r.appendChild(e),{root:r,fill:c,title:n,detail:o,transitionValue:g.value,transitionRow:g.row,frameLabel:_.label,frameValue:_.value,frameRow:_.row}}const Zt=420;function $(r,t,e){t.textContent=e,r.style.visibility=e?"visible":"hidden"}class Jt{constructor(t){u(this,"_el");u(this,"_hideTimeout",null);u(this,"_hiddenCallbacks",[]);u(this,"_drawingAssets",!1);this._el=t}show(){this._hideTimeout&&(clearTimeout(this._hideTimeout),this._hideTimeout=null),this._el.root.classList.remove("hfp-hiding"),this._el.root.classList.add("hfp-visible")}hide(){if(this._el.root.classList.contains("hfp-hiding")){this._hideTimeout||this._scheduleCleanup();return}this._el.root.classList.contains("hfp-visible")&&(this._el.root.classList.add("hfp-hiding"),this._el.root.classList.remove("hfp-visible"),this._scheduleCleanup())}whenHidden(t){const e=this._el.root.classList;e.contains("hfp-visible")||e.contains("hfp-hiding")?this._hiddenCallbacks.push(t):t()}_flushHidden(){const t=this._hiddenCallbacks;this._hiddenCallbacks=[];for(const e of t)e()}reset(){this._hideTimeout&&(clearTimeout(this._hideTimeout),this._hideTimeout=null),this._el.root.classList.remove("hfp-visible","hfp-hiding"),this._drawingAssets=!1,this._flushHidden(),this._el.fill.style.transform="scaleX(0)",$(this._el.transitionRow,this._el.transitionValue,""),$(this._el.frameRow,this._el.frameValue,"")}update(t,e){const i=e==="player"&&t.loading&&!t.ready;if(this._drawingAssets&&!i)return;if(e!=="player"){this.reset();return}if(t.ready||!t.loading){this.hide();return}this._el.root.setAttribute("aria-label","Preparing scene transitions"),this._drawingAssets=!1;const s=typeof t.progress=="number"&&Number.isFinite(t.progress)?t.progress:0,n=typeof t.total=="number"&&Number.isFinite(t.total)?t.total:0,o=n>0?Math.min(1,Math.max(0,s/n)):0,a=Math.min(G.length-1,Math.floor(o*G.length));this._el.title.textContent=G[a]||"Preparing scene transitions",this._el.detail.textContent=t.phase==="cached"?"Loading cached transition frames before playback.":t.phase==="finalizing"?"Uploading transition textures for smooth playback.":"Rendering animated scene samples for shader transitions.",this._el.fill.style.transform=`scaleX(${o})`;const c=t.currentTransition!==void 0&&t.transitionTotal!==void 0?`${t.currentTransition}/${t.transitionTotal}`:n>0?`${s}/${n}`:"",p=t.transitionFrame!==void 0&&t.transitionFrames!==void 0?`${t.transitionFrame}/${t.transitionFrames}`:"";this._el.frameLabel.textContent=t.phase==="cached"?"cached transition frames":t.phase==="finalizing"?"finalizing transition frames":"rendering transition frames",$(this._el.transitionRow,this._el.transitionValue,c),$(this._el.frameRow,this._el.frameValue,p),this._el.root.setAttribute("aria-valuenow",String(Math.round(o*100))),this.show()}showAssetsLoading(t="Loading assets",e="Waiting for images, video and fonts to finish loading."){this.reset(),this._el.title.textContent=t,this._el.detail.textContent=e,this._el.root.setAttribute("aria-label",t),this._drawingAssets=!0,this.show()}hideAssetsLoading(){this._drawingAssets&&this.hide()}get hideTimeout(){return this._hideTimeout}destroy(){this._hideTimeout&&(clearTimeout(this._hideTimeout),this._hideTimeout=null),this._hiddenCallbacks=[]}_scheduleCleanup(){this._hideTimeout&&clearTimeout(this._hideTimeout),this._hideTimeout=setTimeout(()=>{this._el.root.classList.remove("hfp-hiding"),this._hideTimeout=null,this._flushHidden()},Zt)}}function Qt(r){return(r==null?void 0:r.trim().toLowerCase().startsWith("video/"))??!1}function ei(r){const t=document.createElement("video");t.className="hfp-video",t.playsInline=!0,t.preload="metadata";const e=new AbortController,{signal:i}=e;return t.addEventListener("loadedmetadata",()=>r.onMetadata(t),{signal:i}),t.addEventListener("durationchange",()=>r.onDurationChange(t),{signal:i}),t.addEventListener("resize",()=>r.onResize(t),{signal:i}),t.addEventListener("play",()=>r.onPlay(t),{signal:i}),t.addEventListener("pause",()=>r.onPause(t),{signal:i}),t.addEventListener("timeupdate",()=>r.onTimeUpdate(),{signal:i}),t.addEventListener("error",()=>{var n,o;return r.onError(((n=t.error)==null?void 0:n.message)||"Video failed to load",((o=t.error)==null?void 0:o.code)??null)},{signal:i}),{video:t,adapter:{duration:()=>t.duration,time:()=>t.currentTime,seek:n=>{t.currentTime=Fe(n)},play:()=>t.play().catch(n=>{i.aborted||r.onPlayRejected(n)}),pause:()=>t.pause(),timeScale:n=>{t.defaultPlaybackRate=n,t.playbackRate=n}},destroy:()=>{e.abort(),t.pause(),t.removeAttribute("src"),t.load(),t.remove()}}}const ti=.1,ii=5,J="sandbox-origin",Ie=1e4,Q=8e3,ee="assets-loading",M="assets-loading-ui",j="buffering",te="low-power-idle",Oe="disable-click-to-play",x="range-start",I="range-end",Ne=150;function ie(r){return!Number.isFinite(r)||r<=0?1:Math.max(ti,Math.min(ii,r))}class si extends HTMLElement{constructor(){super();u(this,"shadow");u(this,"container");u(this,"sizer",document.createElement("div"));u(this,"iframe");u(this,"posterEl",null);u(this,"controlsApi",null);u(this,"resizeObserver");u(this,"shaderLoader");u(this,"probe");u(this,"_ready",!1);u(this,"_readyDocument",null);u(this,"_connected",!1);u(this,"_assetsReady",!1);u(this,"_painted",!1);u(this,"_pendingPlay",!1);u(this,"_assetsGeneration",0);u(this,"_assetsLoadingShowTimer",null);u(this,"_bufferingShowTimer",null);u(this,"_currentTime",0);u(this,"_duration",0);u(this,"_paused",!0);u(this,"_scrubbing",!1);u(this,"_lastUpdateMs",0);u(this,"_volume",1);u(this,"_compositionWidth",1920);u(this,"_compositionHeight",1080);u(this,"_rescaleWarned",!1);u(this,"_directTimelineAdapter",null);u(this,"_directTimelineClock");u(this,"_parentTickRaf",null);u(this,"_media");u(this,"_scenes",[]);u(this,"_runtimeFps",30);u(this,"_runtimeBridgeReady",!1);u(this,"_runtimeAssetsReadyGeneration",-1);u(this,"_runtimeData",new Map);u(this,"_runtimeDataRequestId",0);u(this,"_pendingRuntimeData",new Map);u(this,"_afterUpdate",null);u(this,"_videoSource",null);u(this,"_runtimeOwnsPlayRange",!1);u(this,"_enteringRange",!1);u(this,"_rangeClampReported","");this.shadow=this.attachShadow({mode:"open"}),ct(this.shadow,rt),{container:this.container,iframe:this.iframe}=pt(),this.sizer.className="hfp-sizer",this.shadow.appendChild(this.sizer),this.shadow.appendChild(this.container);const e=Kt();this.shadow.appendChild(e.root),this.shaderLoader=new Jt(e),this._media=new It({dispatchEvent:i=>this._emit(i),getMuted:()=>this.muted,getVolume:()=>this._volume,getPlaybackRate:()=>this.playbackRate,getCurrentTime:()=>this._currentTime,isPaused:()=>this._paused}),this._directTimelineClock=new yt({onTimeUpdate:(i,s)=>{var n;this._currentTime=i,(n=this.controlsApi)==null||n.updateTime(i,s),this._emit(new CustomEvent("timeupdate",{detail:{currentTime:i}}))},getLoop:()=>this.loop,restart:()=>{var i;this.seek(((i=this._playRange())==null?void 0:i.start)??0),this.play()},onPaused:()=>{var i;this._media.audioOwner==="parent"&&this._media.pauseAll(),this._paused=!0,(i=this.controlsApi)==null||i.updatePlaying(!1),this._emit(new Event("ended"))},onEnded:()=>this.loop}),this.probe=new st(this.iframe,{resolveRuntimeUrl:()=>Ve(this),hostOwnsDeadline:()=>this.hasAttribute("no-load-timeout"),onReady:i=>this._onProbeReady(i),onError:i=>this._emit(new CustomEvent("error",{detail:{message:i}}))}),this.addEventListener("click",i=>{this.disableClickToPlay||ht(i)||(this._paused?this.play():this.pause())}),this.resizeObserver=new ResizeObserver(()=>this._rescale()),this._onMessage=this._onMessage.bind(this),this._onIframeLoad=this._onIframeLoad.bind(this),this.iframe.addEventListener("load",this._onIframeLoad)}static get observedAttributes(){return["src","srcdoc","width","height","controls","muted","audio-locked","volume","poster","playback-rate","audio-src","type",J,se,D,N,M,te,x,I]}connectedCallback(){this._connected=!0,this._applySandboxOriginPolicy(),this.resizeObserver.observe(this),window.addEventListener("message",this._onMessage),this.hasAttribute("controls")&&this._setupControls(),this.hasAttribute("poster")&&(this.posterEl=Pe(this.shadow,this.getAttribute("poster"),this.posterEl)),this.hasAttribute("audio-src")&&this._media.setupFromUrl(this.getAttribute("audio-src")),this.hasAttribute("srcdoc")&&(this.iframe.srcdoc=z(this,this.getAttribute("srcdoc"))),this.hasAttribute("src")&&this._loadSrc(this.getAttribute("src")),!this.hasAttribute("audio-locked")&&this._isLockedHostEnvironment()&&this._applyAudioLock(!0)}disconnectedCallback(){var e;this._connected=!1,this._teardownVideo(),this._sendControl("pause"),this._stopIframeMedia(),this.resizeObserver.disconnect(),window.removeEventListener("message",this._onMessage),this.probe.stop(),this._directTimelineClock.stop(),this._stopParentTickClock(),this._directTimelineAdapter=null,this.shaderLoader.destroy(),this._media.destroy(),(e=this.controlsApi)==null||e.destroy(),this.controlsApi=null,this._paused=!0,this._pendingPlay=!1,this._abandonComposition("Player disconnected before runtime data was applied")}attributeChangedCallback(e,i,s){var n,o,a,c,p;switch(e){case"src":if(!this.isConnected)break;s&&this._navigateSrc(s);break;case"type":{const l=this.getAttribute("src");if(!this.isConnected||l===null||!!this._videoSource===this._wantsVideo())break;this._navigateSrc(l);break}case"srcdoc":if(!this.isConnected)break;if(this._pendingPlay=!1,this._abandonComposition("Composition navigated before runtime data was applied"),s!==null)this._pauseForVideoSwitch(),this._teardownVideo(),this.iframe.srcdoc=z(this,s);else{this.iframe.removeAttribute("srcdoc");const l=this.getAttribute("src");l!==null&&this._wantsVideo()&&this._navigateSrc(l)}break;case J:this._applySandboxOriginPolicy(this.isConnected&&i!==s);break;case"width":this._setCompositionSize(Y(s)??1920,this._compositionHeight);break;case"height":this._setCompositionSize(this._compositionWidth,Y(s)??1080);break;case"controls":s!==null?this._setupControls():((n=this.controlsApi)==null||n.destroy(),this.controlsApi=null);break;case"poster":this.posterEl=Pe(this.shadow,s,this.posterEl);break;case"playback-rate":{const l=ie(parseFloat(s||"1"));this._media.updatePlaybackRate(l),this._sendControl("set-playback-rate",{playbackRate:l}),(a=(o=this._directTimelineAdapter)==null?void 0:o.timeScale)==null||a.call(o,l),(c=this.controlsApi)==null||c.updateSpeed(l),this._emit(new Event("ratechange"));break}case"muted":this._handleMutedChange(s);break;case"audio-locked":this._applyAudioLock(s!==null);break;case"volume":{const l=Math.max(0,Math.min(1,parseFloat(s||"1")));this._volume=l,this._syncVideoAudio(),this._media.updateVolume(l),this._sendControl("set-volume",{volume:l}),(p=this.controlsApi)==null||p.updateVolume(l),this._emit(new Event("volumechange"));break}case"audio-src":s?this._media.setupFromUrl(s):this._media.teardownUrlAudio();break;case M:s==="none"&&this.shaderLoader.hideAssetsLoading();break;case te:this._sendControl("set-idle-heartbeat",{slow:s!==null});break;case x:case I:this._applyPlayRange(!0);break;case D:case N:case se:if(!this.isConnected)break;this._reloadShaderOptions();break}}_applySandboxOriginPolicy(e=!1){this.hasAttribute(J)?this.iframe.sandbox.remove("allow-same-origin"):this.iframe.sandbox.add("allow-same-origin"),e&&this._reloadForSandboxOriginPolicy()}_reloadForSandboxOriginPolicy(){if(this._videoSource)return;this._abandonComposition("Sandbox policy changed before runtime data was applied");const e=this.getAttribute("srcdoc");if(e!==null){this.iframe.srcdoc=z(this,e);return}const i=this.getAttribute("src");i===null?this.iframe.src="about:blank":this._loadSrc(i)}get iframeElement(){return this.iframe}get scenes(){return this._scenes}play(){this._play(!0)}_play(e){var o,a;if(this._ready&&!this._assetsReady){this._pendingPlay=!0;return}this._pendingPlay=!1,(o=this.posterEl)==null||o.remove(),this.posterEl=null;const i=this._ready?this._playRange():null;i?De(this._currentTime,i,this._duration,this._runtimeFps)&&(this.seek(i.start),this._enteringRange=!0):this._duration>0&&this._currentTime>=this._duration&&this.seek(0),this._paused=!1;const s=this._tryDirectTimelinePlay();let n=!1;this._sendDisplayScale(),s||(this._sendControl("play"),this._ready&&!this._directTimelineAdapter?this._startParentTickClock():this._ready||(this._pendingPlay=!0,n=!0)),this._media.audioOwner==="parent"?this._media.playAll():this._media.primeAll(),(a=this.controlsApi)==null||a.updatePlaying(!0),!n&&e&&this._emit(new Event("play")),s&&this._directTimelineAdapter&&this._directTimelineClock.start(this._directTimelineAdapter,()=>this._currentTime,()=>this._duration,()=>this._paused,()=>this._clockStop())}pause(){var e;this._pendingPlay=!1,this._tryDirectTimelinePause()?this._showPausedVideoTime():this._sendControl("pause"),this._directTimelineClock.stop(),this._stopParentTickClock(),this._media.audioOwner==="parent"&&this._media.pauseAll(),this._paused=!0,(e=this.controlsApi)==null||e.updatePlaying(!1),this._emit(new Event("pause"))}stopMedia(){this._sendControl("stop-media"),this._stopIframeMedia(),this._media.stopAdoptedMedia()}seek(e){var i,s;this._pendingPlay=!1,!this._trySyncSeek(e)&&!this._tryDirectTimelineSeek(e)&&this._sendControl("seek",{timeSeconds:e,frame:Math.round(e*this._runtimeFps)}),this._directTimelineClock.stop(),this._stopParentTickClock(),this._currentTime=e,this._media.audioOwner==="parent"&&(this._scrubbing?this._media.scrubAll(e):(this._media.pauseAll(),this._media.seekAll(e))),this._paused=!0,(i=this.controlsApi)==null||i.updatePlaying(!1),(s=this.controlsApi)==null||s.updateTime(this._currentTime,this._duration)}setColorGrading(e,i){this._sendControl("set-color-grading",{target:e,grading:i})}clearColorGrading(e){this._sendControl("set-color-grading",{target:e,grading:null})}setColorGradingCompare(e,i){this._sendControl("set-color-grading-compare",{target:e,compare:i})}clearColorGradingCompare(e){this._sendControl("set-color-grading-compare",{target:e,compare:{enabled:!1}})}setRuntimeData(e,i){if(!/^[a-z][a-z0-9-]{0,63}$/.test(e))throw new Error(`Invalid HyperFrames runtime-data channel: ${e}`);if(typeof structuredClone!="function")throw new Error("HyperFrames runtime data requires structuredClone support; refusing an unverified payload");const s=structuredClone(i);this._runtimeData.set(e,s),this._deliverRuntimeData(e,s)}clearRuntimeData(e){if(!/^[a-z][a-z0-9-]{0,63}$/.test(e))throw new Error(`Invalid HyperFrames runtime-data channel: ${e}`);this._runtimeData.delete(e),this._deliverRuntimeDataClear(e)}get currentTime(){return this._currentTime}set currentTime(e){this.seek(e)}get duration(){return this._duration}get compositionWidth(){return this._compositionWidth}get compositionHeight(){return this._compositionHeight}get paused(){return this._paused}get ready(){return this._ready}get assetsReady(){return this._assetsReady}get painted(){return this._painted}get playbackRate(){return ie(parseFloat(this.getAttribute("playback-rate")||"1"))}set playbackRate(e){this.setAttribute("playback-rate",String(ie(e)))}get shaderCaptureScale(){return Yt(this)}set shaderCaptureScale(e){this.setAttribute(D,String(e))}get shaderLoading(){return K(this)}set shaderLoading(e){e==="composition"?this.removeAttribute(N):this.setAttribute(N,e)}get assetsLoadingUi(){return this.getAttribute(M)==="none"?"none":"player"}set assetsLoadingUi(e){e==="none"?this.setAttribute(M,"none"):this.removeAttribute(M)}get muted(){return this.hasAttribute("muted")}set muted(e){e?this.setAttribute("muted",""):this.removeAttribute("muted")}get audioLocked(){return this.hasAttribute("audio-locked")}set audioLocked(e){e?this.setAttribute("audio-locked",""):this.removeAttribute("audio-locked")}_isLockedHostEnvironment(){if(typeof navigator>"u")return!1;const e=navigator.userAgent||"";return/\bClaude\/\d/.test(e)&&/\bElectron\b/.test(e)}_isAudioLocked(){return this.hasAttribute("audio-locked")||this._isLockedHostEnvironment()}_isSlideshowPlayer(){return this.closest("hyperframes-slideshow")!==null}_handleMutedChange(e){var i;if(e===null&&this._isAudioLocked()){this.setAttribute("muted","");return}this._media.updateMuted(e!==null),this._syncVideoAudio(),this._setIframeMediaMuted(e!==null),this._sendControl("set-muted",{muted:e!==null}),(i=this.controlsApi)==null||i.updateMuted(e!==null),this._emit(new Event("volumechange"))}_applyAudioLock(e){var i;e&&(this.muted=!0),(i=this.controlsApi)==null||i.setVolumeControlsHidden(e)}get volume(){return this._volume}set volume(e){this.setAttribute("volume",String(Math.max(0,Math.min(1,e))))}get disableClickToPlay(){return this.hasAttribute(Oe)}set disableClickToPlay(e){this.toggleAttribute(Oe,e)}get loop(){return this.hasAttribute("loop")}set loop(e){e?this.setAttribute("loop",""):this.removeAttribute("loop")}get rangeStart(){return this._readSeconds(x)}set rangeStart(e){this._writeSeconds(x,e)}get rangeEnd(){return this._readSeconds(I)}set rangeEnd(e){this._writeSeconds(I,e)}_readSeconds(e){const i=this.getAttribute(e);return i===null?null:Number(i)}_writeSeconds(e,i){i==null?this.removeAttribute(e):this.setAttribute(e,String(i))}_hasPlayRange(){return this.hasAttribute(x)||this.hasAttribute(I)}_playRange(){return Le(this.rangeStart,this.rangeEnd,this._duration).range}_sendPlayRange(e){const i=(e==null?void 0:e.end)??null;this._sendControl("set-play-range",{startSeconds:(e==null?void 0:e.start)??null,endSeconds:i})}_applyPlayRange(e){const{range:i,clamped:s}=Le(this.rangeStart,this.rangeEnd,this._duration);this._sendPlayRange(i),this._ready&&(this._reportRangeClamp(i,s),i&&e&&!this._pendingPlay&&this._moveIntoPlayRange(i))}_reportRangeClamp(e,i){const s=i?`${this.rangeStart},${this.rangeEnd},${this._duration}`:"";if(s===this._rangeClampReported||(this._rangeClampReported=s,!i))return;const n={rangeStart:(e==null?void 0:e.start)??null,rangeEnd:(e==null?void 0:e.end)??null};this._emit(new CustomEvent("rangeclamped",{detail:{...n,duration:this._duration}}))}_moveIntoPlayRange(e){De(this._currentTime,e,this._duration,this._runtimeFps)&&(this._paused?this.seek(e.start):this._jumpWhilePlaying(e.start))}_jumpWhilePlaying(e){this._directTimelineAdapter?(this._directTimelineAdapter.seek(e,!1),this._currentTime=e):this._runtimeOwnsPlayRange||(this.seek(e),this._enteringRange=!0,this._play(!1))}_clockStop(){const e=this._playRange(),i=(e==null?void 0:e.end)??this._duration;if(!e)return{end:i,shown:i};const s=re(e,this._duration,this._runtimeFps);return{end:i,shown:s<i?(s+i)/2:s}}_sendControl(e,i={}){try{const s=this.iframe.contentWindow;return s?(s.postMessage({...i,source:"hf-parent",type:"control",action:e,...Ye(this._runtimeFps)},"*"),!0):((e==="set-runtime-data"||e==="clear-runtime-data")&&this._rejectRuntimeDataDelivery(i.channel,i.requestId,"Composition iframe is unavailable"),!1)}catch(s){return(e==="set-runtime-data"||e==="clear-runtime-data")&&this._rejectRuntimeDataDelivery(i.channel,i.requestId,s instanceof Error?s.message:String(s)),!1}}_deliverRuntimeData(e,i){if(!this.isConnected||!this._runtimeBridgeReady)return;const s=this._beginRuntimeDataDelivery(e);this._trySetRuntimeDataDirect(e,i,s)||this._sendControl("set-runtime-data",{channel:e,payload:i,requestId:s})}_deliverRuntimeDataClear(e){if(!this.isConnected||!this._runtimeBridgeReady)return;const i=this._beginRuntimeDataDelivery(e);this._tryClearRuntimeDataDirect(e,i)||this._sendControl("clear-runtime-data",{channel:e,requestId:i})}_trySetRuntimeDataDirect(e,i,s){var n;try{const o=(n=this.iframe.contentWindow)==null?void 0:n.__hyperframes;return typeof(o==null?void 0:o.setRuntimeData)!="function"?!1:(o.setRuntimeData(e,i,s),!0)}catch{return!1}}_tryClearRuntimeDataDirect(e,i){var s;try{const n=(s=this.iframe.contentWindow)==null?void 0:s.__hyperframes;return typeof(n==null?void 0:n.clearRuntimeData)!="function"?!1:(n.clearRuntimeData(e,i),!0)}catch{return!1}}_replayRuntimeData(){for(const[e,i]of this._runtimeData)this._deliverRuntimeData(e,i)}_beginRuntimeDataDelivery(e){const i=this._pendingRuntimeData.get(e);i&&window.clearTimeout(i.timeoutId),this._runtimeDataRequestId+=1;const s=this._runtimeDataRequestId,n=window.setTimeout(()=>{this._rejectRuntimeDataDelivery(e,s,`Runtime data delivery timed out after ${Ie}ms`)},Ie);return this._pendingRuntimeData.set(e,{requestId:s,timeoutId:n}),s}_resolveRuntimeDataDelivery(e,i){const s=this._takeRuntimeDataDelivery(e,i);s&&this._emit(new CustomEvent("runtimedataapplied",{detail:{channel:e,requestId:s.requestId}}))}_rejectRuntimeDataDelivery(e,i,s){const n=this._takeRuntimeDataDelivery(e,i);n&&this._emit(new CustomEvent("runtimedataerror",{detail:{channel:e,requestId:n.requestId,message:typeof s=="string"?s:String(s)}}))}_takeRuntimeDataDelivery(e,i){if(typeof e!="string"||typeof i!="number"||!Number.isSafeInteger(i))return null;const s=this._pendingRuntimeData.get(e);return!s||s.requestId!==i?null:(window.clearTimeout(s.timeoutId),this._pendingRuntimeData.delete(e),s)}_rejectAllRuntimeDataDeliveries(e){for(const[i,s]of[...this._pendingRuntimeData])this._rejectRuntimeDataDelivery(i,s.requestId,e)}_getSameOriginIframeDocument(){try{return this.iframe.contentDocument}catch{return null}}_setIframeMediaMuted(e){const i=this._getSameOriginIframeDocument();if(i)for(const s of i.querySelectorAll("video, audio"))A(s)&&(s.muted=e||s.defaultMuted)}_stopIframeMedia(){const e=this._getSameOriginIframeDocument();if(e)for(const i of e.querySelectorAll("video, audio"))A(i)&&i.pause()}_replayBridgeState(){this._sendControl("set-muted",{muted:this.muted}),this._sendControl("set-volume",{volume:this._volume}),this._sendControl("set-playback-rate",{playbackRate:this.playbackRate}),this._sendControl("set-native-media-sync-disabled",{disabled:this._isSlideshowPlayer()}),this._sendControl("set-web-audio-media-disabled",{disabled:this._isSlideshowPlayer()}),this._sendControl("set-idle-heartbeat",{slow:this.hasAttribute(te)}),this._sendDisplayScale()}_sendDisplayScale(){const e=Xe(this.iframe);e&&this._sendControl("set-display-scale",{scale:e})}_reloadShaderOptions(){if(!this._videoSource){if(this._abandonComposition("Shader options changed before runtime data was applied"),this.hasAttribute("srcdoc")){this.iframe.srcdoc=z(this,this.getAttribute("srcdoc")||"");return}this.hasAttribute("src")&&this._loadSrc(this.getAttribute("src")||"")}}_navigateSrc(e){this._pendingPlay=!1,this._pauseForVideoSwitch(),this._abandonComposition("Composition navigated before runtime data was applied"),this._loadSrc(e)}_wantsVideo(){return Qt(this.getAttribute("type"))&&!this.hasAttribute("srcdoc")}_pauseForVideoSwitch(){var e;!this._videoSource&&!this._wantsVideo()||(this._paused=!0,(e=this.controlsApi)==null||e.updatePlaying(!1))}_loadSrc(e){if(this._wantsVideo()){this._loadVideo(e);return}this._teardownVideo(),this.iframe.src=Xt(this,e)}_loadVideo(e){var n,o;this._videoSource||(this._videoSource=ei({onMetadata:a=>this._applyThenEmit(()=>this._onVideoReady(a)),onDurationChange:a=>this._applyTimelineDuration(a.duration),onResize:a=>this._applyVideoSize(a),onPlay:a=>{!a.paused&&this._paused&&this.play()},onPause:a=>{a.paused&&!a.ended&&!this._paused&&this.pause()},onTimeUpdate:()=>{document.hidden&&this._playRange()&&this._directTimelineClock.poll()},onError:(a,c)=>{this._paused||this.pause(),this._emit(new CustomEvent("error",{detail:{message:a,code:c}}))},onPlayRejected:a=>this._onVideoPlayRejected(a)}),this.container.appendChild(this._videoSource.video),this.iframe.hidden=!0,this.iframe.src="about:blank"),this.probe.stop();const{video:i,adapter:s}=this._videoSource;this._directTimelineAdapter=s,this._currentTime=0,this._duration=0,(n=this.controlsApi)==null||n.updateTime(0,0),this._syncVideoAudio(),(o=s.timeScale)==null||o.call(s,this.playbackRate),i.src=e}_teardownVideo(){this._videoSource&&(this._videoSource.destroy(),this._videoSource=null,this.iframe.hidden=!1)}_syncVideoAudio(){this._videoSource&&(this._videoSource.video.muted=this.muted,this._videoSource.video.volume=this._volume)}_onVideoReady(e){this._applyTimelineDuration(e.duration),this._applyVideoSize(e),this._ready=!0,this._dispatchReady(),this._waitForAssetsReady(null),this._afterEvents(()=>{this.hasAttribute("autoplay")&&this._paused&&this.play()})}_applyTimelineDuration(e){var i;!Number.isFinite(e)||e<=0||(this._setDuration(e),(i=this.controlsApi)==null||i.updateTime(this._currentTime,e))}_applyVideoSize(e){e.videoWidth>0&&e.videoHeight>0&&this._setCompositionSize(e.videoWidth,e.videoHeight)}_onVideoPlayRejected(e){e instanceof DOMException&&e.name==="NotAllowedError"&&(this._paused||this.pause(),this._emit(new CustomEvent("playbackerror",{detail:{source:"video",error:e}})))}_trySyncSeek(e){if(this._videoSource)return!1;try{const i=this.iframe.contentWindow,s=i==null?void 0:i.__player;return typeof(s==null?void 0:s.seek)!="function"?!1:(s.seek.call(s,e),!0)}catch{return!1}}_withDirectTimeline(e){const i=this._videoSource?null:this.probe.resolveDirectTimelineAdapter(),s=i||this._directTimelineAdapter;if(!s)return!1;try{return e(s),i&&i!==this._directTimelineAdapter&&this._applyTimelineDuration(i.duration()),this._directTimelineAdapter=s,!0}catch{return!1}}_tryDirectTimelineSeek(e){return this._withDirectTimeline(i=>{i.seek(e,!1),i.pause()})}_tryDirectTimelinePlay(){return this._withDirectTimeline(e=>void e.play())}_tryDirectTimelinePause(){return this._withDirectTimeline(e=>void e.pause())}_showPausedVideoTime(){var e;this._videoSource&&(this._currentTime=this._videoSource.video.currentTime,(e=this.controlsApi)==null||e.updateTime(this._currentTime,this._duration),this._emit(new CustomEvent("timeupdate",{detail:{currentTime:this._currentTime}})))}_startParentTickClock(){this._stopParentTickClock();const e=()=>{if(this._paused){this._parentTickRaf=null;return}this._sendControl("tick"),this._parentTickRaf=requestAnimationFrame(e)};this._parentTickRaf=requestAnimationFrame(e)}_stopParentTickClock(){this._parentTickRaf!==null&&(cancelAnimationFrame(this._parentTickRaf),this._parentTickRaf=null)}_onMessage(e){this._videoSource||this.probe.failed||this._applyThenEmit(()=>this._handleRuntimeMessage(e))}_handleRuntimeMessage(e){Wt(e,this.iframe.contentWindow,{getPlaybackState:()=>({currentTime:this._currentTime,duration:this._duration,paused:this._paused,lastUpdateMs:this._lastUpdateMs,enteringRange:this._enteringRange}),setPlaybackState:({currentTime:i,duration:s,paused:n,lastUpdateMs:o,enteringRange:a})=>{this._enteringRange=a===!0,this._currentTime=i,this._setDuration(s),this._paused=n,this._lastUpdateMs=o},getShaderLoadingMode:()=>K(this),shaderLoader:this.shaderLoader,setCompositionSize:(i,s)=>this._setCompositionSize(i,s),sendControl:(i,s)=>this._sendControl(i,s),getIframeDoc:()=>this.iframe.contentDocument,onRuntimeReady:()=>{this._runtimeBridgeReady=!0,this._replayBridgeState(),this._hasPlayRange()&&this._sendPlayRange(this._playRange()),this._replayRuntimeData()},onRuntimeAssetsReady:()=>{this._runtimeAssetsReadyGeneration===this._assetsGeneration&&this._settleAssetsReady(this._assetsGeneration)},onRuntimeDataApplied:(i,s)=>this._resolveRuntimeDataDelivery(i,s),onRuntimeDataError:(i,s,n)=>this._rejectRuntimeDataDelivery(i,s,n),onRuntimeTimelineReady:(i,s)=>this._onRuntimeTimelineReady(i,s),setBuffering:i=>this._setBuffering(i),setRuntimeFps:i=>{this._runtimeFps=i},setRuntimeOwnsPlayRange:i=>{this._runtimeOwnsPlayRange=i},shouldPromoteMediaAutoplayFallback:()=>!this._isSlideshowPlayer(),setScenes:i=>{this._scenes=i,this._emit(new CustomEvent("scenes",{detail:{scenes:i}}))},updateControlsTime:(i,s)=>{var n;return(n=this.controlsApi)==null?void 0:n.updateTime(i,s)},updateControlsPlaying:i=>{var s;return(s=this.controlsApi)==null?void 0:s.updatePlaying(i)},dispatchEvent:i=>this._emit(i),seek:i=>this.seek(i),play:()=>this.play(),getLoop:()=>this.loop,getPlayRange:()=>this._playRange(),media:this._media})}_onRuntimeTimelineReady(e,i){var n;if(this._ready)return;this.probe.stop(),this._setDuration(e),this._directTimelineAdapter=null,this._ready=!0,(n=this.controlsApi)==null||n.updateTime(this._currentTime,e),this._dispatchReady();const s=this._getSameOriginIframeDocument();s&&this._media.setupFromIframe(s),this._replayBridgeState(),this._setIframeMediaMuted(this.muted),this._waitForAssetsReady(s,i),this._playWhenWanted()}_onProbeReady(e){this._applyThenEmit(()=>this._applyProbeResult(e))}_applyProbeResult({duration:e,adapter:i,compositionSize:s}){var o;this._setDuration(e),this._directTimelineAdapter=i.kind==="direct-timeline"?i.timeline:null,s&&this._setCompositionSize(s.width,s.height),this._ready=!0,(o=this.controlsApi)==null||o.updateTime(0,e),this._dispatchReady();const n=this._getSameOriginIframeDocument();n&&this._media.setupFromIframe(n),this._setIframeMediaMuted(this.muted),this._waitForAssetsReady(n),this._playWhenWanted()}_waitForAssetsReady(e,i){this._clearAssetsLoadingShowTimer(),this._assetsReady=!1,this._painted=!1;const s=++this._assetsGeneration;if(!e){i===!1?(this._runtimeAssetsReadyGeneration=s,this._startAssetsLoadingOverlayTimer(s),setTimeout(()=>this._settleAssetsReady(s),Q)):this._settleAssetsReady(s);return}Ke(e,({timedOut:n})=>{s===this._assetsGeneration&&(n&&this._warnStuckAssets(e),this._settleAssetsReady(s))},{timeoutMs:Q}),this._assetsReady||this._startAssetsLoadingOverlayTimer(s)}_startAssetsLoadingOverlayTimer(e){this._assetsLoadingShowTimer=setTimeout(()=>{this._assetsLoadingShowTimer=null,!(e!==this._assetsGeneration||this._assetsReady)&&(this.setAttribute(ee,""),this.assetsLoadingUi!=="none"&&this.shaderLoader.showAssetsLoading())},Ne)}_setBuffering(e){if(e){if(this._bufferingShowTimer!==null||this.hasAttribute(j))return;this._bufferingShowTimer=setTimeout(()=>{this._bufferingShowTimer=null,this.setAttribute(j,""),this.assetsLoadingUi!=="none"&&this.shaderLoader.showAssetsLoading("Buffering","")},Ne);return}this._bufferingShowTimer!==null&&clearTimeout(this._bufferingShowTimer),this._bufferingShowTimer=null,this.hasAttribute(j)&&(this.removeAttribute(j),this.shaderLoader.hideAssetsLoading())}_hasPendingFirstFrameAssets(e){const{pendingMedia:i,pendingImages:s,fontsLoading:n}=Se(e,{scope:Ee});return i.length>0||s.length>0||n}_warnStuckAssets(e){const{pendingMedia:i,pendingImages:s,fontsLoading:n}=Se(e,{scope:Ee}),o=e.defaultView;console.warn(`[hyperframes-player] assets-loading timed out after ${Q}ms, playing anyway`,{stuckMedia:i.map(a=>a.currentSrc||a.getAttribute("src")||`<${a.tagName.toLowerCase()}>`),stuckImages:s.map(a=>a.currentSrc||a.getAttribute("src")||"<img>"),fontsLoading:n,computeReady:(o==null?void 0:o.__renderReady)===!0,documentHidden:e.hidden===!0})}_settleAssetsReady(e){e!==this._assetsGeneration||this._assetsReady||(this._clearAssetsLoadingShowTimer(),this._assetsReady=!0,this.removeAttribute(ee),this.shaderLoader.hideAssetsLoading(),this._emit(new Event("assetsready")),this.shaderLoader.whenHidden(()=>{e===this._assetsGeneration&&(this._painted=!0,this._emit(new Event("painted")))}),this._afterEvents(()=>{this._pendingPlay&&this.play()}))}_abandonComposition(e){this.probe.stop(),this._ready=!1,this._readyDocument=null,this._invalidateAssetsWait(),this._releaseDocument(),this._runtimeBridgeReady=!1,this._rejectAllRuntimeDataDeliveries(e)}_releaseDocument(){this._runtimeOwnsPlayRange=!1,this._enteringRange=!1,this._directTimelineAdapter=null,this._directTimelineClock.stop(),this._stopParentTickClock(),this._setBuffering(!1),this.shaderLoader.reset(),this._media.resetForIframeLoad()}_invalidateAssetsWait(){this._clearAssetsLoadingShowTimer(),this._assetsReady=!1,this._painted=!1,this._assetsGeneration++,this.removeAttribute(ee),this.shaderLoader.hide()}_clearAssetsLoadingShowTimer(){this._assetsLoadingShowTimer!==null&&(clearTimeout(this._assetsLoadingShowTimer),this._assetsLoadingShowTimer=null)}_dispatchReady(){this._readyDocument=this._getSameOriginIframeDocument();const e={duration:this._duration,compositionWidth:this._compositionWidth,compositionHeight:this._compositionHeight};this._emit(new CustomEvent("ready",{detail:e})),this._rescale(),this._rangeClampReported="",this._hasPlayRange()&&this._applyPlayRange(!0)}_setDuration(e){e!==this._duration&&(this._duration=e,this._ready&&(this._emit(new CustomEvent("durationchange",{detail:{duration:e}})),this._hasPlayRange()&&this._applyPlayRange(!1)))}_setCompositionSize(e,i){const s=e!==this._compositionWidth||i!==this._compositionHeight;if(this._compositionWidth=e,this._compositionHeight=i,this.sizer.style.aspectRatio=`${e} / ${i}`,this._rescale(),!s)return;const n={compositionWidth:e,compositionHeight:i};this._emit(new CustomEvent("resize",{detail:n}))}_applyThenEmit(e){if(this._afterUpdate){e();return}const i=[];this._afterUpdate=i;const s=[],n=o=>{try{o()}catch(a){s.push(a)}};n(e);for(const o of i)n(o);if(this._afterUpdate=null,s.length>0)throw s[0]}_afterEvents(e){this._afterUpdate?this._afterUpdate.push(e):e()}_playWhenWanted(){this._afterEvents(()=>{(this.hasAttribute("autoplay")||this._pendingPlay)&&this.play()})}_emit(e){this._afterEvents(()=>this.dispatchEvent(e))}_rescale(){const e=mt(this,this.iframe,this._compositionWidth,this._compositionHeight);e&&this._sendDisplayScale(),!e&&this._ready&&!this._rescaleWarned&&(this._rescaleWarned=!0,console.warn("[hyperframes-player] rescale no-op after ready: zero-size player element",{src:this.getAttribute("src"),offsetWidth:this.offsetWidth,offsetHeight:this.offsetHeight,compositionWidth:this._compositionWidth,compositionHeight:this._compositionHeight}))}_onIframeLoad(){if(!this._connected||this._videoSource)return;const e=this._getSameOriginIframeDocument();if(this._ready&&e===this._readyDocument){e&&this._hasPendingFirstFrameAssets(e)&&this._waitForAssetsReady(e);return}this._ready=!1,this._invalidateAssetsWait(),this._releaseDocument(),this.probe.start()}_setupControls(){this.controlsApi||(this.controlsApi=lt(this.shadow,this.muted,this._volume,this.getAttribute("speed-presets"),{onPlay:()=>this.play(),onPause:()=>this.pause(),onSeek:e=>this.seek(e*this._duration),onScrubStart:()=>{this._scrubbing=!0},onScrubEnd:()=>{this._scrubbing=!1,this.seek(this._currentTime)},onSpeedChange:e=>void(this.playbackRate=e),onMuteToggle:()=>void(this.muted=!this.muted),onVolumeChange:e=>void(this.volume=e)},this._isAudioLocked()),this.controlsApi.updateTime(this._currentTime,this._duration),this.controlsApi.updatePlaying(!this._paused),this.controlsApi.updateSpeed(this.playbackRate))}get _audioOwner(){return this._media.audioOwner}get _parentMedia(){return this._media.entries}_mirrorParentMediaTime(e,i){this._media.mirrorTime(e,i)}_promoteToParentProxy(){let e=null;try{e=this.iframe.contentDocument}catch{}this._media.promoteToParentProxy(e,(i,s)=>this._mirrorParentMediaTime(i,s)),this._sendControl("set-media-output-muted",{muted:!0})}_observeDynamicMedia(e){this._media.setupFromIframe(e)}}customElements.get("hyperframes-player")||customElements.define("hyperframes-player",si);export{si as HyperframesPlayer,dt as SPEED_PRESETS,k as formatSpeed,Ce as formatTime};
|
|
477
|
+
`,nt='<svg width="24" height="24" viewBox="46 21 54 56" fill="currentColor"><path d="M87.5129 57.5141L56.9696 73.5433C52.8371 75.7098 48.7046 73.2553 49.6688 69.2104L58.9483 30.1391C59.9125 26.0942 65.2097 23.6397 68.3154 25.8062L91.2447 41.8354C96.4668 45.4796 94.4631 53.8699 87.5129 57.5141Z"/></svg>',ot='<svg width="24" height="24" viewBox="0 0 18 18" fill="currentColor"><rect x="3" y="2" width="4" height="14"/><rect x="11" y="2" width="4" height="14"/></svg>',Te='<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3z"/><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z"/><path d="M14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/></svg>',Re='<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3z"/><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z"/></svg>',at='<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3z"/><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z" opacity="0.3"/><line x1="18" y1="7" x2="14" y2="17" stroke="currentColor" stroke-width="2"/></svg>',dt=[.25,.5,1,1.5,2,4];function M(r){return Number.isInteger(r)?`${r}x`:`${r}x`}function Ce(r){if(!Number.isFinite(r)||r<0)return"0:00";const t=Math.floor(r),e=Math.floor(t/60),i=t%60;return`${e}:${i.toString().padStart(2,"0")}`}function ut(r,t,e={}){const i=e.speedPresets??dt,s=document.createElement("div");s.className="hfp-controls",s.addEventListener("click",d=>{d.stopPropagation()});const n=document.createElement("button");n.className="hfp-play-btn",n.type="button",n.innerHTML=`<span class="hfp-ico hfp-ico-play">${nt}</span><span class="hfp-ico hfp-ico-pause">${ot}</span>`,n.setAttribute("aria-label","Play");const o=document.createElement("div");o.className="hfp-scrubber";const a=document.createElement("div");a.className="hfp-progress",a.style.width="0%",o.appendChild(a);const c=document.createElement("span");c.className="hfp-time",c.textContent="0:00 / 0:00";const p=document.createElement("div");p.className="hfp-speed-wrap";const l=document.createElement("button");l.className="hfp-speed-btn",l.type="button",l.textContent="1x",l.setAttribute("aria-label","Playback speed: 1x");const g=document.createElement("div");g.className="hfp-speed-menu",g.setAttribute("role","menu");for(const d of i){const h=document.createElement("button");h.className="hfp-speed-option",h.type="button",h.setAttribute("role","menuitem"),h.dataset.speed=String(d),h.textContent=M(d),d===1&&h.classList.add("hfp-active"),g.appendChild(h)}p.appendChild(g),p.appendChild(l);const _=document.createElement("div");_.className="hfp-volume-wrap";const m=document.createElement("button");m.className="hfp-mute-btn",m.type="button",m.innerHTML=Te,m.setAttribute("aria-label","Mute");const y=document.createElement("div");y.className="hfp-volume-slider-wrap";const f=document.createElement("div");f.className="hfp-volume-slider",f.setAttribute("role","slider"),f.setAttribute("aria-label","Volume"),f.setAttribute("aria-valuemin","0"),f.setAttribute("aria-valuemax","100"),f.setAttribute("aria-valuenow","100"),f.tabIndex=0;const b=document.createElement("div");b.className="hfp-volume-fill",b.style.width="100%",f.appendChild(b),y.appendChild(f),_.appendChild(y),_.appendChild(m),e.audioLocked&&(_.style.display="none"),s.appendChild(n),s.appendChild(o),s.appendChild(c),s.appendChild(_),s.appendChild(p),r.appendChild(s);let P=!1,w=!1,T=1,R=null;i.indexOf(1);const U=(d,h)=>d?at:h===0||h<.5?Re:Te;n.addEventListener("click",d=>{d.stopPropagation(),P?t.onPause():t.onPlay()}),m.addEventListener("click",d=>{d.stopPropagation(),t.onMuteToggle()});let C=!1;const V=d=>{const h=f.getBoundingClientRect(),v=Math.max(0,Math.min(1,(d-h.left)/h.width));T=v,b.style.width=`${v*100}%`,f.setAttribute("aria-valuenow",String(Math.round(v*100))),w&&v>0&&t.onMuteToggle(),m.innerHTML=U(w,v),t.onVolumeChange(v)};f.addEventListener("mousedown",d=>{d.stopPropagation(),C=!0,V(d.clientX)});const oe=d=>{C&&V(d.clientX)},ae=()=>{C=!1};document.addEventListener("mousemove",oe),document.addEventListener("mouseup",ae),f.addEventListener("touchstart",d=>{C=!0;const h=d.touches[0];h&&V(h.clientX)},{passive:!0});const de=d=>{if(C){const h=d.touches[0];h&&V(h.clientX)}},ue=()=>{C=!1};document.addEventListener("touchmove",de,{passive:!0}),document.addEventListener("touchend",ue);const le=.05;f.addEventListener("keydown",d=>{let h=T;if(d.key==="ArrowRight"||d.key==="ArrowUp")h=Math.min(1,T+le);else if(d.key==="ArrowLeft"||d.key==="ArrowDown")h=Math.max(0,T-le);else return;d.preventDefault(),d.stopPropagation(),T=h,b.style.width=`${h*100}%`,f.setAttribute("aria-valuenow",String(Math.round(h*100))),w&&h>0&&t.onMuteToggle(),m.innerHTML=U(w,h),t.onVolumeChange(h)});const he=d=>{for(const h of g.querySelectorAll(".hfp-speed-option"))h.classList.toggle("hfp-active",h.dataset.speed===String(d))};l.addEventListener("click",d=>{d.stopPropagation();const h=g.classList.toggle("hfp-open");l.setAttribute("aria-expanded",String(h))}),g.addEventListener("click",d=>{d.stopPropagation();const h=d.target.closest(".hfp-speed-option");if(!h)return;const v=parseFloat(h.dataset.speed);i.indexOf(v),l.textContent=M(v),l.setAttribute("aria-label",`Playback speed: ${M(v)}`),he(v),g.classList.remove("hfp-open"),l.setAttribute("aria-expanded","false"),t.onSpeedChange(v)});const ce=()=>{g.classList.remove("hfp-open"),l.setAttribute("aria-expanded","false")};document.addEventListener("click",ce);const H=d=>{const h=o.getBoundingClientRect(),v=Math.max(0,Math.min(1,(d-h.left)/h.width));t.onSeek(v)};let S=!1;o.addEventListener("mousedown",d=>{var h;d.stopPropagation(),S=!0,(h=t.onScrubStart)==null||h.call(t),H(d.clientX)});const pe=d=>{S&&H(d.clientX)},me=()=>{var d;S&&(S=!1,(d=t.onScrubEnd)==null||d.call(t))};document.addEventListener("mousemove",pe),document.addEventListener("mouseup",me),o.addEventListener("touchstart",d=>{var v;S=!0,(v=t.onScrubStart)==null||v.call(t);const h=d.touches[0];h&&H(h.clientX)},{passive:!0});const fe=d=>{if(S){const h=d.touches[0];h&&H(h.clientX)}},_e=()=>{var d;S&&(S=!1,(d=t.onScrubEnd)==null||d.call(t))};document.addEventListener("touchmove",fe,{passive:!0}),document.addEventListener("touchend",_e);const ge=()=>P&&!S&&!C&&!s.querySelector(":focus-visible"),ye=()=>{s.classList.remove("hfp-hidden"),R&&clearTimeout(R),R=setTimeout(()=>{ge()&&s.classList.add("hfp-hidden")},3e3)},E=r instanceof ShadowRoot?r.host:r,L=()=>ye(),ve=()=>{ge()&&s.classList.add("hfp-hidden")};return E.addEventListener("mousemove",L),E.addEventListener("keydown",L),E.addEventListener("focusin",L),E.addEventListener("mouseleave",ve),{updateTime(d,h){const v=h>0?Math.min(d,h):d,He=h>0?v/h*100:0;a.style.width=`${He}%`,c.textContent=`${Ce(v)} / ${Ce(h)}`},updatePlaying(d){const h=d!==P;P=d,n.classList.toggle("hfp-playing",d),n.setAttribute("aria-label",d?"Pause":"Play"),d?h&&ye():(R&&clearTimeout(R),s.classList.remove("hfp-hidden"))},updateSpeed(d){i.indexOf(d),l.textContent=M(d),l.setAttribute("aria-label",`Playback speed: ${M(d)}`),he(d)},updateMuted(d){w=d,m.innerHTML=U(d,T),m.setAttribute("aria-label",d?"Unmute":"Mute")},updateVolume(d){T=d,b.style.width=`${d*100}%`,f.setAttribute("aria-valuenow",String(Math.round(d*100))),m.innerHTML=U(w,d)},setVolumeControlsHidden(d){_.style.display=d?"none":""},show(){s.style.display=""},hide(){s.style.display="none"},destroy(){document.removeEventListener("mousemove",pe),document.removeEventListener("mouseup",me),document.removeEventListener("touchmove",fe),document.removeEventListener("touchend",_e),document.removeEventListener("mousemove",oe),document.removeEventListener("mouseup",ae),document.removeEventListener("touchmove",de),document.removeEventListener("touchend",ue),document.removeEventListener("click",ce),E.removeEventListener("mousemove",L),E.removeEventListener("keydown",L),E.removeEventListener("focusin",L),E.removeEventListener("mouseleave",ve),R&&clearTimeout(R),s.remove()}}}function lt(r,t,e,i,s,n=!1){const o=i?i.split(",").map(Number).filter(p=>!isNaN(p)&&p>0):void 0,a={...o?{speedPresets:o}:{},audioLocked:n},c=ut(r,s,a);return c.updateMuted(t),c.updateVolume(e),c}function Pe(r,t,e){return t?(e||(e=document.createElement("img"),e.className="hfp-poster",r.appendChild(e)),e.src=t,e):(e==null||e.remove(),null)}function ht(r){return r.composedPath().some(t=>t instanceof HTMLElement&&t.classList.contains("hfp-controls"))}let W=null;function ct(r,t){if(typeof CSSStyleSheet<"u")try{W||(W=new CSSStyleSheet,W.replaceSync(t)),r.adoptedStyleSheets=[W];return}catch{}const e=document.createElement("style");e.textContent=t,r.appendChild(e)}function pt(){const r=document.createElement("div");r.className="hfp-container";const t=document.createElement("iframe");return t.className="hfp-iframe",t.sandbox.add("allow-scripts","allow-same-origin"),t.allow="autoplay; fullscreen",t.referrerPolicy="no-referrer",t.title="HyperFrames Composition",r.appendChild(t),{container:r,iframe:t}}function mt(r,t,e,i){const s=r.offsetWidth,n=r.offsetHeight;if(s===0||n===0)return!1;const o=Math.min(s/e,n/i);return t.style.width=`${e}px`,t.style.height=`${i}px`,t.style.transform=`translate(-50%, -50%) scale(${o})`,!0}const ft=100,_t=.001;function gt(r,t,e){if(e.end<=0)return!1;const i=e.shown<e.end&&t>0?t+_t:0;return r+i>=e.end}class yt{constructor(t){u(this,"_raf",null);u(this,"_lastUpdateMs",0);u(this,"_tick",null);this._callbacks=t}start(t,e,i,s,n){this.stop();let o=null,a=0,c=0;const p=()=>{if(s()){this._raf=null;return}let l;try{l=t.time()}catch{this._raf=null;return}const g=i(),_=n();_.end>0&&(l=Math.min(l,_.end));const m=o===null?0:l-o;m!==0&&(c=Math.min(m,a),a=m),o=l;const y=gt(l,c,_);y&&(l=_.shown);const f=performance.now();if((f-this._lastUpdateMs>ft||y)&&(this._lastUpdateMs=f,this._callbacks.onTimeUpdate(l,g)),y){if(this._callbacks.getLoop()){this._callbacks.restart();return}try{t.pause(),_.shown<_.end&&t.seek(_.shown,!1)}catch{}this._callbacks.onPaused(),this._raf=null;return}this._raf=requestAnimationFrame(p)};this._tick=p,this._raf=requestAnimationFrame(p)}poll(){this._raf===null||!this._tick||(cancelAnimationFrame(this._raf),this._tick())}stop(){this._raf!==null&&(cancelAnimationFrame(this._raf),this._raf=null)}get isRunning(){return this._raf!==null}}function vt(r){const t=Array.from(r.querySelectorAll("[data-composition-id]"));if(t.length===0)return r.body?[r.body]:[];const e=[];for(const i of t)At(i)||e.push(i);return bt(r),e}function bt(r){const t=r.body;if(!t||typeof console>"u"||typeof console.warn!="function")return;const e=t.querySelectorAll("audio[data-start], video[data-start]");if(e.length===0)return;const i=[];for(const s of e)s.closest("[data-composition-id]")||i.push(s);i.length!==0&&console.warn(`[hyperframes-player] selectMediaObserverTargets: composition hosts are present, but ${i.length} body-level timed media element(s) sit outside every [data-composition-id] subtree and will not be observed. Move them inside a composition host or the parent-frame proxy will never adopt them.`,i)}function At(r){let t=r.parentElement;for(;t;){if(t.hasAttribute("data-composition-id"))return!0;t=t.parentElement}return!1}const wt=1e-5;function Fe(r){return r+wt}function St(){const{userAgent:r,maxTouchPoints:t}=navigator;return/iP(hone|ad|od)/.test(r)||/Macintosh/.test(r)&&t>1}function Et(){const{userAgent:r}=navigator;return/AppleWebKit/.test(r)&&!/Chrom(e|ium)\/|Edg\/|Android/.test(r)}const X=.04,Tt=.5,Rt=.03,Ct=[[.3,.25],[.1,.1]],Pt=.01,Lt=.1,Dt=.1,kt=.65,D=new WeakMap,q=new WeakSet;function Mt(r,t,e,i,s=r.tagName==="AUDIO"){var g;const n=Math.abs(t);if(s&&Et())return D.delete(r),{rate:e,seek:i&&n>kt};i&&n<=X&&q.delete(r);const o=!q.has(r)||n>Tt;if(s&&i&&n>Dt&&o)return D.delete(r),q.add(r),{rate:e,seek:!0};const a=Math.sign(t),c=D.get(r);if(n>X)D.set(r,a);else if(c!==a||n<=Pt)return D.delete(r),{rate:e,seek:!1};const p=((g=Ct.find(([_])=>n>_))==null?void 0:g[1])??Rt,l=s?Math.min(p,Lt):p;return{rate:e*(1+a*l),seek:!1}}function It(r){D.delete(r),q.delete(r)}const xt=.004,Ot=1.5;class Nt{constructor(t){u(this,"_entries",[]);u(this,"_mediaObserver");u(this,"_playbackErrorPosted",!1);u(this,"_audioOwner","runtime");u(this,"_urlAudioEntry",null);u(this,"_urlAudioSrc",null);u(this,"_dispatchEvent");u(this,"_getMuted");u(this,"_getVolume");u(this,"_getPlaybackRate");u(this,"_getCurrentTime");u(this,"_isPaused");this._dispatchEvent=t.dispatchEvent,this._getMuted=t.getMuted,this._getVolume=t.getVolume,this._getPlaybackRate=t.getPlaybackRate,this._getCurrentTime=t.getCurrentTime,this._isPaused=t.isPaused}get audioOwner(){return this._audioOwner}get entries(){return this._entries}resetForIframeLoad(){this._playbackErrorPosted=!1;const t=this._audioOwner==="parent";this._audioOwner="runtime",this.pauseAll();for(const e of this._entries)e!==this._urlAudioEntry&&(e.el.src="");this._entries=this._urlAudioEntry?[this._urlAudioEntry]:[],this._urlAudioSrc&&!this._urlAudioEntry&&(this._urlAudioEntry=this._createEntry(this._urlAudioSrc,"audio",0,1/0)),this.teardownObserver(),t&&this._dispatchEvent(new CustomEvent("audioownershipchange",{detail:{owner:"runtime",reason:"iframe-reload"}}))}destroy(){this.teardownObserver();for(const t of this._entries)t.el.pause(),t.el.src="";this._entries=[],this._urlAudioEntry=null,this._urlAudioSrc=null,this._audioOwner="runtime",this._playbackErrorPosted=!1}updateMuted(t){for(const e of this._entries)e.el.muted=t}updateVolume(t){for(const e of this._entries)e.el.volume=t}updatePlaybackRate(t){for(const e of this._entries)e.el.playbackRate=t}_playEntry(t){t.el.src&&t.el.play().catch(e=>this._reportPlaybackError(e))}_playEntryIfActive(t){this._refreshEntryBounds(t),this._inWindow(t,this._getCurrentTime())&&this._playEntry(t)}_refreshEntryBounds(t){var i;if(!((i=t.source)!=null&&i.isConnected))return;const e=be(t.source);t.start=e.start??0,t.mediaStart=Ae(t.source).mediaStart,t.duration=e.duration!=null&&e.duration>0?e.duration:Number.POSITIVE_INFINITY}_inWindow(t,e){return Be(e,t.start,t.start+t.duration)}_preseekUpcoming(t,e){const i=t.start-e;i<=0||i>Ot||!t.el.paused||Math.abs(t.el.currentTime-t.mediaStart)>X&&this._seekTo(t,t.mediaStart)}_seekTo(t,e,i=!1){const s=i?(t.seekLatency??0)*this._getPlaybackRate():0;t.seekIssuedAt=i?performance.now():void 0,t.el.currentTime=Fe(e+s)}_noteSeekLanded(t){if(t.seekIssuedAt===void 0)return;const e=(performance.now()-t.seekIssuedAt)/1e3;t.seekLatency=t.seekLatency===void 0?e:(t.seekLatency+e)/2,t.seekIssuedAt=void 0}_releaseSteering(t){It(t.el),t.lastOffset=void 0;const e=this._getPlaybackRate();t.el.playbackRate!==e&&(t.el.playbackRate=e)}_mediaTime(t,e){return e-t.start+t.mediaStart}_gateEntryPlayback(t,e){return this._inWindow(t,e)?(this._audioOwner==="parent"&&!this._isPaused()&&t.el.paused&&this._playEntry(t),!0):(t.el.paused||t.el.pause(),this._releaseSteering(t),!1)}playAll(){for(const t of this._entries)this._playEntryIfActive(t)}primeAll(){if(St())for(const t of this._entries)t.el.paused&&(t.el.play().catch(()=>{}),t.el.pause())}pauseAll(){for(const t of this._entries)t.el.pause()}stopAdoptedMedia(){for(const t of this._entries)t.source&&t.el.pause()}seekAll(t){for(const e of this._entries)this._refreshEntryBounds(e),this._inWindow(e,t)&&this._jumpTo(e,this._mediaTime(e,t))}scrubAll(t){for(const e of this._entries)this._refreshEntryBounds(e),this._inWindow(e,t)?(this._jumpTo(e,this._mediaTime(e,t)),this._playEntry(e)):e.el.paused||e.el.pause()}mirrorTime(t,e){const i=(e==null?void 0:e.force)===!0;for(const s of this._entries){this._refreshEntryBounds(s),this._preseekUpcoming(s,t);const n=s.el.paused;if(!this._gateEntryPlayback(s,t))continue;const o=this._mediaTime(s,t),a=o-s.el.currentTime;if(i||n){Math.abs(a)>X&&this._jumpTo(s,o);continue}this._steer(s,o,a)}}_steer(t,e,i){const s=t.lastOffset!==void 0&&Math.abs(i-t.lastOffset)<xt;t.lastOffset=i;const{rate:n,seek:o}=Mt(t.el,i,this._getPlaybackRate(),s,!0);o?this._jumpTo(t,e,!0):Math.abs(t.el.playbackRate-n)>1e-6&&(t.el.playbackRate=n)}_jumpTo(t,e,i=!1){this._seekTo(t,e,i),this._releaseSteering(t)}promoteToParentProxy(t,e){if(this._audioOwner==="parent")return;if(this._audioOwner="parent",t)for(const s of t.querySelectorAll("video, audio"))A(s)&&(s.muted=!0);for(const s of[...this._entries])this._repointToSource(s);const i=this._getCurrentTime();e?e(i,{force:!0}):this.mirrorTime(i,{force:!0}),this._isPaused()||this.playAll(),this._dispatchEvent(new CustomEvent("audioownershipchange",{detail:{owner:"parent",reason:"autoplay-blocked"}}))}setupFromIframe(t){const e=t.querySelectorAll("audio[data-start], video[data-start]");for(const i of e)A(i)&&this._adoptIframeMedia(i);this._observeDynamicMedia(t)}setupFromUrl(t){if(this._urlAudioSrc===t&&this._urlAudioEntry)return;this.teardownUrlAudio();const e=this._createEntry(t,"audio",0,1/0);this._urlAudioEntry=e,this._urlAudioSrc=t,e&&this._audioOwner==="parent"&&!this._isPaused()&&(this.mirrorTime(this._getCurrentTime(),{force:!0}),this.playAll())}teardownUrlAudio(){const t=this._urlAudioEntry;if(this._urlAudioEntry=null,this._urlAudioSrc=null,!t)return;t.el.pause(),t.el.src="";const e=this._entries.indexOf(t);e!==-1&&this._entries.splice(e,1)}teardownObserver(){var t;(t=this._mediaObserver)==null||t.disconnect(),this._mediaObserver=void 0}_reportPlaybackError(t){this._playbackErrorPosted||(this._playbackErrorPosted=!0,this._dispatchEvent(new CustomEvent("playbackerror",{detail:{source:"parent-proxy",error:t}})))}_createEntry(t,e,i,s,n){if(!n&&this._urlTaken(t))return null;const o=e==="video"?document.createElement("video"):new Audio;o.preload="auto";const a=n==null?void 0:n.getAttribute("crossorigin");a!=null&&o.setAttribute("crossorigin",a),o.src=t,o.load(),o.muted=this._getMuted(),o.volume=this._getVolume();const c=this._getPlaybackRate();c!==1&&(o.playbackRate=c);const p={el:o,start:i,duration:s,mediaStart:n?Ae(n).mediaStart:0,source:n};return o.addEventListener("seeked",()=>this._noteSeekLanded(p)),this._entries.push(p),p}_resolveIframeMediaSrc(t){var i;const e=t.getAttribute("src")||((i=t.querySelector("source"))==null?void 0:i.getAttribute("src"));return e?new URL(e,t.ownerDocument.baseURI).href:null}_adoptIframeMedia(t){if(t.preload==="metadata"||t.preload==="none"||this._entries.some(c=>c.source===t)||t.tagName==="VIDEO"&&t.hasAttribute("muted"))return;const e=this._resolveIframeMediaSrc(t);if(!e)return;const i=be(t),s=i.start??0,n=i.duration??Number.POSITIVE_INFINITY,o=t.tagName==="VIDEO"?"video":"audio",a=this._createEntry(e,o,s,n,t);a&&this._audioOwner==="parent"&&(this.mirrorTime(this._getCurrentTime(),{force:!0}),this._isPaused()||this._playEntryIfActive(a))}_followIframeMediaSrc(t){const e=this._entries.find(i=>i.source===t);if(!e)return this._adoptIframeMedia(t);this._audioOwner!=="parent"||!this._repointToSource(e)||(this.mirrorTime(this._getCurrentTime(),{force:!0}),this._isPaused()||this._playEntryIfActive(e))}_urlTaken(t){return this._entries.some(e=>e.source&&!e.source.isConnected?!1:(e.source&&this._resolveIframeMediaSrc(e.source)||e.el.src)===t)}_repointToSource(t){const e=t.source?this._resolveIframeMediaSrc(t.source):null;return!e||t.el.src===e?!1:(t.el.src=e,t.el.load(),!0)}_detachIframeMedia(t){const e=this._entries.find(i=>i.source===t);e&&this._removeEntry(e)}_removeEntry(t){t.el.pause(),t.el.src="",this._entries.splice(this._entries.indexOf(t),1)}_observeDynamicMedia(t){if(this.teardownObserver(),typeof MutationObserver>"u"||!t.body)return;const e=new MutationObserver(n=>{for(const o of n){if(o.type==="attributes"&&o.attributeName==="src"){const a=o.target;A(a)&&a.matches("audio[data-start], video[data-start]")&&this._followIframeMediaSrc(a);continue}if(o.type==="attributes"&&o.attributeName==="preload"){const a=o.target;A(a)&&a.matches("audio[data-start], video[data-start]")&&(a.preload==="auto"?this._adoptIframeMedia(a):this._detachIframeMedia(a));continue}for(const a of o.addedNodes){if(!we(a))continue;const c=[];A(a)&&a.matches("audio[data-start], video[data-start]")&&c.push(a);const p=a.querySelectorAll("audio[data-start], video[data-start]");for(const l of p)A(l)&&c.push(l);for(const l of c)this._adoptIframeMedia(l)}for(const a of o.removedNodes){if(!we(a))continue;const c=[];A(a)&&a.matches("audio[data-start], video[data-start]")&&c.push(a);const p=a.querySelectorAll("audio[data-start], video[data-start]");for(const l of p)A(l)&&c.push(l);for(const l of c)this._detachIframeMedia(l)}}}),i={childList:!0,subtree:!0,attributes:!0,attributeFilter:["preload","src"]},s=vt(t);for(const n of s)e.observe(n,i);this._mediaObserver=e}}function Le(r,t,e){if(r===null&&t===null)return{range:null,clamped:!1};const i=r??0,s=t!==null&&e>0&&t>e,n=s?e:t,o=n??(e>0?e:1/0);return!(i>=0)||!(o>i)?{range:null,clamped:!0}:{range:{start:i,end:n},clamped:s}}function re(r,t,e){const i=r.end??t;return i<t?qe(r.start,i,e):i}function De(r,t,e,i){return r<t.start||r>=re(t,e,i)}const Ft=100;function Ut(r,t){return typeof r.currentTime=="number"&&Number.isFinite(r.currentTime)?r.currentTime:(r.frame??0)/t}function Ue(r,t,e){return e<=0?!1:r.ended===!0?!0:r.ended===!1&&!r.isPlaying?!1:t>=e}function Vt(r,t,e,i,s,n){const{duration:o}=e;if(!s){const a=Ue(r,t,o);return{start:0,shownAtEnd:o,atEnd:a,stopRuntime:!1,entering:!1}}if(r.ownsRange){const a=i&&r.ended===!0&&!r.isPlaying;return{start:s.start,shownAtEnd:t,atEnd:a,stopRuntime:!1,entering:!1}}return Ht(r,t,e,i,s,n)}function Ht(r,t,e,i,s,n){const o=s.end??e.duration,a=e.enteringRange===!0&&(t<s.start||t>=o);return{start:s.start,shownAtEnd:re(s,e.duration,n),atEnd:i&&!a&&Ue(r,t,o),stopRuntime:r.isPlaying,entering:a}}function Wt(r,t,e,i){var w;const s=Ut(r,t),n=!e.paused,o=n||r.isPlaying,a=(w=i.getPlayRange)==null?void 0:w.call(i),c=Vt(r,s,e,o,a,t),{atEnd:p,start:l}=c,g=e.duration>0?Math.min(s,e.duration):s,_=p?c.shownAtEnd:g,m=!r.isPlaying,y=p&&o;if(y&&i.getLoop())return i.media.audioOwner==="parent"&&i.media.pauseAll(),i.seek(l),i.play(),{...e,currentTime:l,paused:!1,enteringRange:!0};const f={...e,currentTime:_,paused:m,enteringRange:c.entering};i.media.audioOwner==="parent"&&(n&&m?i.media.pauseAll():!n&&!m&&i.media.playAll(),i.media.mirrorTime(_));const b=performance.now(),P=m!==e.paused;return(b-e.lastUpdateMs>Ft||P)&&(f.lastUpdateMs=b,i.updateControlsTime(_,e.duration),i.updateControlsPlaying(!m),i.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:_}}))),y&&(c.stopRuntime&&i.seek(_),i.media.audioOwner==="parent"&&i.media.pauseAll(),f.paused=!0,i.updateControlsPlaying(!1),i.dispatchEvent(new Event("ended"))),f}function zt(r){return Array.isArray(r)?r.filter(t=>typeof t=="object"&&t!==null&&typeof t.id=="string"&&typeof t.start=="number"&&typeof t.duration=="number"):[]}function $t(r,t,e){var o,a,c,p,l,g,_;if(r.source!==t)return;const i=r.data;if(!i||i.source!=="hf-preview")return;const s=Ge(i);if(s.status==="unsupported"){e.dispatchEvent(new CustomEvent("runtimeprotocolerror",{detail:{code:s.code,receivedVersion:s.receivedVersion}}));return}(o=e.setRuntimeFps)==null||o.call(e,s.fps);const n=s.status==="supported"&&s.metadata.capabilities.includes("play-range");if((a=e.setRuntimeOwnsPlayRange)==null||a.call(e,n),i.type==="shader-transition-state"){const m=i.state&&typeof i.state=="object"?i.state:{};e.shaderLoader.update(m,e.getShaderLoadingMode()),e.dispatchEvent(new CustomEvent("shadertransitionstate",{detail:{compositionId:i.compositionId,state:m}}));return}if(i.type==="ready"){e.onRuntimeReady();return}if(i.type==="assets-ready"){(c=e.onRuntimeAssetsReady)==null||c.call(e,i.timedOut===!0);return}if(i.type==="runtime-data-error"){(p=e.onRuntimeDataError)==null||p.call(e,i.channel,i.requestId,i.message);return}if(i.type==="runtime-data-applied"){(l=e.onRuntimeDataApplied)==null||l.call(e,i.channel,i.requestId);return}if(i.type==="state"){e.setPlaybackState(Wt({frame:i.frame??0,currentTime:i.currentTime,ended:typeof i.ended=="boolean"?i.ended:void 0,isPlaying:!!i.isPlaying,ownsRange:n},s.fps,e.getPlaybackState(),e)),(g=e.setBuffering)==null||g.call(e,i.buffering===!0);return}if(i.type==="media-autoplay-blocked"){if(((_=e.shouldPromoteMediaAutoplayFallback)==null?void 0:_.call(e))===!1)return;let m=null;try{m=e.getIframeDoc()}catch{}e.media.promoteToParentProxy(m,(y,f)=>e.media.mirrorTime(y,f)),e.sendControl("set-media-output-muted",{muted:!0});return}if(i.type==="timeline"&&i.durationInFrames>0){const m=Number(i.durationSeconds),y=Number(i.durationInFrames),f=Number.isFinite(m)&&m>0?m:y/s.fps;if(Number.isFinite(i.compositionWidth)&&i.compositionWidth>0&&Number.isFinite(i.compositionHeight)&&i.compositionHeight>0&&e.setCompositionSize(i.compositionWidth,i.compositionHeight),Number.isFinite(f)&&f>0){const b=e.getPlaybackState();e.setPlaybackState({...b,duration:f}),e.updateControlsTime(b.currentTime,f),e.onRuntimeTimelineReady(f,typeof i.assetsReady=="boolean"?i.assetsReady:void 0)}e.setScenes(zt(i.scenes));return}i.type==="stage-size"&&Number.isFinite(i.width)&&i.width>0&&Number.isFinite(i.height)&&i.height>0&&e.setCompositionSize(i.width,i.height)}function jt(r,t){return r.includes(t)?!0:/hyperframe\.runtime\.iife\.js|__hyperframes\s*=/.test(r)}const Bt=new Set([">"," "," ",`
|
|
478
|
+
`,"\r","\f"]);function Z(r,t){const e=r.toLowerCase(),i=`<${t}`;let s=0;for(;s<e.length;){const n=e.indexOf(i,s);if(n<0)return null;const o=e[n+i.length];if(Bt.has(o)){const a=e.indexOf(">",n+i.length);return a<0?null:{index:n,end:a+1}}s=n+i.length}return null}function qt(r,t){if(!r||jt(r,t))return r;const e=`<script src="${t}"><\/script>`,i=Z(r,"head");if(i)return r.slice(0,i.end)+e+r.slice(i.end);const s=Z(r,"body");if(s)return r.slice(0,s.index)+e+r.slice(s.index);const n=Z(r,"html");return n?r.slice(0,n.end)+e+r.slice(n.end):e+r}const k="shader-capture-scale",N="shader-loading",se="runtime-src",ke="__hf_shader_capture_scale",Me="__hf_shader_loading",G=["Preparing scene transitions","Sampling outgoing scene motion","Sampling incoming scene motion","Caching transition frames","Finalizing transition preview"];function ne(r){if(r===null)return null;const t=Number(r);return!Number.isFinite(t)||t<=0?null:String(Math.min(1,Math.max(.25,t)))}function Gt(r){if(r===null||r.trim()==="")return"composition";const t=r.trim().toLowerCase();return t==="none"||t==="false"||t==="0"||t==="off"?"none":t==="player"||t==="true"||t==="1"||t==="on"?"player":"composition"}function Ie(r,t){return r.filter(e=>e!==""&&e.split("=")[0]!==t)}function Yt(r,t,e){const i=r.indexOf("#"),s=i>=0?r.slice(0,i):r,n=i>=0?r.slice(i):"",o=s.indexOf("?"),a=o>=0?s.slice(0,o):s,c=o>=0?s.slice(o+1):"";let p=Ie(c.split("&"),ke);p=Ie(p,Me),t!==null&&p.push(`${ke}=${encodeURIComponent(t)}`),e!=="composition"&&p.push(`${Me}=${encodeURIComponent(e)}`);const l=p.join("&");return`${a}${l?`?${l}`:""}${n}`}function Xt(r,t,e){if(t===null&&e==="composition")return r;const i=[];t!==null&&i.push(`window.__HF_SHADER_CAPTURE_SCALE=${JSON.stringify(t)};`),e!=="composition"&&i.push(`window.__HF_SHADER_LOADING=${JSON.stringify(e)};`);const s=`<script data-hyperframes-player-shader-options>${i.join("")}<\/script>`;return/<head\b[^>]*>/i.test(r)?r.replace(/<head\b[^>]*>/i,n=>`${n}${s}`):/<html\b[^>]*>/i.test(r)?r.replace(/<html\b[^>]*>/i,n=>`${n}${s}`):`${s}${r}`}function K(r){return Gt(r.getAttribute(N))}function Kt(r){return Number(ne(r.getAttribute(k))??"1")}function Zt(r,t){return Yt(t,ne(r.getAttribute(k)),K(r))}function z(r,t){return qt(Xt(t,ne(r.getAttribute(k)),K(r)),Ve(r))}function Ve(r){var e;const t=(e=r.getAttribute(se))==null?void 0:e.trim();if(!t)return B;try{const i=new URL(t,document.baseURI),s=i.protocol==="http:"||i.protocol==="https:",n=i.hostname==="127.0.0.1"||i.hostname==="localhost"||i.hostname==="[::1]";return s&&(n||i.origin===location.origin)?i.href:B}catch{return B}}function Jt(){const r=document.createElement("div");r.className="hfp-shader-loader",r.setAttribute("role","status"),r.setAttribute("aria-live","polite"),r.setAttribute("aria-label","Preparing scene transitions"),r.setAttribute("data-hyperframes-ignore",""),r.draggable=!1;const t=m=>{m.preventDefault(),m.stopPropagation()};for(const m of["selectstart","dragstart","pointerdown","mousedown","click","dblclick","contextmenu","touchstart"])r.addEventListener(m,t,{capture:!0});const e=document.createElement("div");e.className="hfp-shader-loader-panel",e.draggable=!1;const i=document.createElement("div");i.className="hfp-shader-loader-mark",i.draggable=!1,i.innerHTML=['<svg width="78" height="78" viewBox="0 0 100 100" fill="none" aria-hidden="true" draggable="false">','<path d="M10.1851 57.8021L33.1145 73.8313C36.2202 75.9978 41.5173 73.5433 42.4816 69.4984L51.7611 30.4271C52.7253 26.3822 48.5802 23.9277 44.4602 26.0942L13.917 42.1235C6.96677 45.7676 4.97564 54.1579 10.1851 57.8021Z" fill="url(#hfp-shader-loader-grad-left)"/>','<path d="M87.5129 57.5141L56.9696 73.5433C52.8371 75.7098 48.7046 73.2553 49.6688 69.2104L58.9483 30.1391C59.9125 26.0942 65.2097 23.6397 68.3154 25.8062L91.2447 41.8354C96.4668 45.4796 94.4631 53.8699 87.5129 57.5141Z" fill="url(#hfp-shader-loader-grad-right)"/>',"<defs>",'<linearGradient id="hfp-shader-loader-grad-left" x1="48.5676" y1="25" x2="44.7804" y2="71.9384" gradientUnits="userSpaceOnUse">','<stop stop-color="#06E3FA"/>','<stop offset="1" stop-color="#4FDB5E"/>',"</linearGradient>",'<linearGradient id="hfp-shader-loader-grad-right" x1="54.8282" y1="73.8392" x2="72.0989" y2="32.8932" gradientUnits="userSpaceOnUse">','<stop stop-color="#06E3FA"/>','<stop offset="1" stop-color="#4FDB5E"/>',"</linearGradient>","</defs>","</svg>"].join("");const s=document.createElement("div");s.className="hfp-shader-loader-title";const n=document.createElement("span");n.className="hfp-shader-loader-title-text",n.textContent=G[0],s.appendChild(n);const o=document.createElement("div");o.className="hfp-shader-loader-detail",o.textContent="Rendering animated scene samples for shader transitions.";const a=document.createElement("div");a.className="hfp-shader-loader-track",a.setAttribute("aria-hidden","true");const c=document.createElement("div");c.className="hfp-shader-loader-fill",a.appendChild(c);const p=document.createElement("div");p.className="hfp-shader-loader-progress";const l=m=>{const y=document.createElement("div");y.className="hfp-shader-loader-row";const f=document.createElement("span");f.className="hfp-shader-loader-label",f.textContent=m;const b=document.createElement("span");return b.className="hfp-shader-loader-value",y.appendChild(f),y.appendChild(b),p.appendChild(y),{row:y,label:f,value:b}},g=l("transition"),_=l("transition frame");return e.appendChild(i),e.appendChild(s),e.appendChild(o),e.appendChild(a),e.appendChild(p),r.appendChild(e),{root:r,fill:c,title:n,detail:o,transitionValue:g.value,transitionRow:g.row,frameLabel:_.label,frameValue:_.value,frameRow:_.row}}const Qt=420;function $(r,t,e){t.textContent=e,r.style.visibility=e?"visible":"hidden"}class ei{constructor(t){u(this,"_el");u(this,"_hideTimeout",null);u(this,"_hiddenCallbacks",[]);u(this,"_drawingAssets",!1);this._el=t}show(){this._hideTimeout&&(clearTimeout(this._hideTimeout),this._hideTimeout=null),this._el.root.classList.remove("hfp-hiding"),this._el.root.classList.add("hfp-visible")}hide(){if(this._el.root.classList.contains("hfp-hiding")){this._hideTimeout||this._scheduleCleanup();return}this._el.root.classList.contains("hfp-visible")&&(this._el.root.classList.add("hfp-hiding"),this._el.root.classList.remove("hfp-visible"),this._scheduleCleanup())}whenHidden(t){const e=this._el.root.classList;e.contains("hfp-visible")||e.contains("hfp-hiding")?this._hiddenCallbacks.push(t):t()}_flushHidden(){const t=this._hiddenCallbacks;this._hiddenCallbacks=[];for(const e of t)e()}reset(){this._hideTimeout&&(clearTimeout(this._hideTimeout),this._hideTimeout=null),this._el.root.classList.remove("hfp-visible","hfp-hiding"),this._drawingAssets=!1,this._flushHidden(),this._el.fill.style.transform="scaleX(0)",$(this._el.transitionRow,this._el.transitionValue,""),$(this._el.frameRow,this._el.frameValue,"")}update(t,e){const i=e==="player"&&t.loading&&!t.ready;if(this._drawingAssets&&!i)return;if(e!=="player"){this.reset();return}if(t.ready||!t.loading){this.hide();return}this._el.root.setAttribute("aria-label","Preparing scene transitions"),this._drawingAssets=!1;const s=typeof t.progress=="number"&&Number.isFinite(t.progress)?t.progress:0,n=typeof t.total=="number"&&Number.isFinite(t.total)?t.total:0,o=n>0?Math.min(1,Math.max(0,s/n)):0,a=Math.min(G.length-1,Math.floor(o*G.length));this._el.title.textContent=G[a]||"Preparing scene transitions",this._el.detail.textContent=t.phase==="cached"?"Loading cached transition frames before playback.":t.phase==="finalizing"?"Uploading transition textures for smooth playback.":"Rendering animated scene samples for shader transitions.",this._el.fill.style.transform=`scaleX(${o})`;const c=t.currentTransition!==void 0&&t.transitionTotal!==void 0?`${t.currentTransition}/${t.transitionTotal}`:n>0?`${s}/${n}`:"",p=t.transitionFrame!==void 0&&t.transitionFrames!==void 0?`${t.transitionFrame}/${t.transitionFrames}`:"";this._el.frameLabel.textContent=t.phase==="cached"?"cached transition frames":t.phase==="finalizing"?"finalizing transition frames":"rendering transition frames",$(this._el.transitionRow,this._el.transitionValue,c),$(this._el.frameRow,this._el.frameValue,p),this._el.root.setAttribute("aria-valuenow",String(Math.round(o*100))),this.show()}showAssetsLoading(t="Loading assets",e="Waiting for images, video and fonts to finish loading."){this.reset(),this._el.title.textContent=t,this._el.detail.textContent=e,this._el.root.setAttribute("aria-label",t),this._drawingAssets=!0,this.show()}hideAssetsLoading(){this._drawingAssets&&this.hide()}get hideTimeout(){return this._hideTimeout}destroy(){this._hideTimeout&&(clearTimeout(this._hideTimeout),this._hideTimeout=null),this._hiddenCallbacks=[]}_scheduleCleanup(){this._hideTimeout&&clearTimeout(this._hideTimeout),this._hideTimeout=setTimeout(()=>{this._el.root.classList.remove("hfp-hiding"),this._hideTimeout=null,this._flushHidden()},Qt)}}function ti(r){return(r==null?void 0:r.trim().toLowerCase().startsWith("video/"))??!1}function ii(r){const t=document.createElement("video");t.className="hfp-video",t.playsInline=!0,t.preload="metadata";const e=new AbortController,{signal:i}=e;return t.addEventListener("loadedmetadata",()=>r.onMetadata(t),{signal:i}),t.addEventListener("durationchange",()=>r.onDurationChange(t),{signal:i}),t.addEventListener("resize",()=>r.onResize(t),{signal:i}),t.addEventListener("play",()=>r.onPlay(t),{signal:i}),t.addEventListener("pause",()=>r.onPause(t),{signal:i}),t.addEventListener("timeupdate",()=>r.onTimeUpdate(),{signal:i}),t.addEventListener("error",()=>{var n,o;return r.onError(((n=t.error)==null?void 0:n.message)||"Video failed to load",((o=t.error)==null?void 0:o.code)??null)},{signal:i}),{video:t,adapter:{duration:()=>t.duration,time:()=>t.currentTime,seek:n=>{t.currentTime=Fe(n)},play:()=>t.play().catch(n=>{i.aborted||r.onPlayRejected(n)}),pause:()=>t.pause(),timeScale:n=>{t.defaultPlaybackRate=n,t.playbackRate=n}},destroy:()=>{e.abort(),t.pause(),t.removeAttribute("src"),t.load(),t.remove()}}}const si=.1,ri=5,J="sandbox-origin",xe=1e4,Q=8e3,ee="assets-loading",I="assets-loading-ui",j="buffering",te="low-power-idle",Oe="disable-click-to-play",x="range-start",O="range-end",Ne=150;function ie(r){return!Number.isFinite(r)||r<=0?1:Math.max(si,Math.min(ri,r))}class ni extends HTMLElement{constructor(){super();u(this,"shadow");u(this,"container");u(this,"sizer",document.createElement("div"));u(this,"iframe");u(this,"posterEl",null);u(this,"controlsApi",null);u(this,"resizeObserver");u(this,"shaderLoader");u(this,"probe");u(this,"_ready",!1);u(this,"_readyDocument",null);u(this,"_connected",!1);u(this,"_assetsReady",!1);u(this,"_painted",!1);u(this,"_pendingPlay",!1);u(this,"_assetsGeneration",0);u(this,"_assetsLoadingShowTimer",null);u(this,"_bufferingShowTimer",null);u(this,"_currentTime",0);u(this,"_duration",0);u(this,"_paused",!0);u(this,"_scrubbing",!1);u(this,"_lastUpdateMs",0);u(this,"_volume",1);u(this,"_compositionWidth",1920);u(this,"_compositionHeight",1080);u(this,"_rescaleWarned",!1);u(this,"_directTimelineAdapter",null);u(this,"_directTimelineClock");u(this,"_parentTickRaf",null);u(this,"_media");u(this,"_scenes",[]);u(this,"_runtimeFps",30);u(this,"_runtimeBridgeReady",!1);u(this,"_runtimeAssetsReadyGeneration",-1);u(this,"_runtimeData",new Map);u(this,"_runtimeDataRequestId",0);u(this,"_pendingRuntimeData",new Map);u(this,"_afterUpdate",null);u(this,"_videoSource",null);u(this,"_runtimeOwnsPlayRange",!1);u(this,"_enteringRange",!1);u(this,"_rangeClampReported","");this.shadow=this.attachShadow({mode:"open"}),ct(this.shadow,rt),{container:this.container,iframe:this.iframe}=pt(),this.sizer.className="hfp-sizer",this.shadow.appendChild(this.sizer),this.shadow.appendChild(this.container);const e=Jt();this.shadow.appendChild(e.root),this.shaderLoader=new ei(e),this._media=new Nt({dispatchEvent:i=>this._emit(i),getMuted:()=>this.muted,getVolume:()=>this._volume,getPlaybackRate:()=>this.playbackRate,getCurrentTime:()=>this._currentTime,isPaused:()=>this._paused}),this._directTimelineClock=new yt({onTimeUpdate:(i,s)=>{var n;this._currentTime=i,(n=this.controlsApi)==null||n.updateTime(i,s),this._emit(new CustomEvent("timeupdate",{detail:{currentTime:i}}))},getLoop:()=>this.loop,restart:()=>{var i;this.seek(((i=this._playRange())==null?void 0:i.start)??0),this.play()},onPaused:()=>{var i;this._media.audioOwner==="parent"&&this._media.pauseAll(),this._paused=!0,(i=this.controlsApi)==null||i.updatePlaying(!1),this._emit(new Event("ended"))},onEnded:()=>this.loop}),this.probe=new st(this.iframe,{resolveRuntimeUrl:()=>Ve(this),hostOwnsDeadline:()=>this.hasAttribute("no-load-timeout"),onReady:i=>this._onProbeReady(i),onError:i=>this._emit(new CustomEvent("error",{detail:{message:i}}))}),this.addEventListener("click",i=>{this.disableClickToPlay||ht(i)||(this._paused?this.play():this.pause())}),this.resizeObserver=new ResizeObserver(()=>this._rescale()),this._onMessage=this._onMessage.bind(this),this._onIframeLoad=this._onIframeLoad.bind(this),this.iframe.addEventListener("load",this._onIframeLoad)}static get observedAttributes(){return["src","srcdoc","width","height","controls","muted","audio-locked","volume","poster","playback-rate","audio-src","type",J,se,k,N,I,te,x,O]}connectedCallback(){this._connected=!0,this._applySandboxOriginPolicy(),this.resizeObserver.observe(this),window.addEventListener("message",this._onMessage),this.hasAttribute("controls")&&this._setupControls(),this.hasAttribute("poster")&&(this.posterEl=Pe(this.shadow,this.getAttribute("poster"),this.posterEl)),this.hasAttribute("audio-src")&&this._media.setupFromUrl(this.getAttribute("audio-src")),this.hasAttribute("srcdoc")&&(this.iframe.srcdoc=z(this,this.getAttribute("srcdoc"))),this.hasAttribute("src")&&this._loadSrc(this.getAttribute("src")),!this.hasAttribute("audio-locked")&&this._isLockedHostEnvironment()&&this._applyAudioLock(!0)}disconnectedCallback(){var e;this._connected=!1,this._teardownVideo(),this._sendControl("pause"),this._stopIframeMedia(),this.resizeObserver.disconnect(),window.removeEventListener("message",this._onMessage),this.probe.stop(),this._directTimelineClock.stop(),this._stopParentTickClock(),this._directTimelineAdapter=null,this.shaderLoader.destroy(),this._media.destroy(),(e=this.controlsApi)==null||e.destroy(),this.controlsApi=null,this._paused=!0,this._pendingPlay=!1,this._abandonComposition("Player disconnected before runtime data was applied")}attributeChangedCallback(e,i,s){var n,o,a,c,p;switch(e){case"src":if(!this.isConnected)break;s&&this._navigateSrc(s);break;case"type":{const l=this.getAttribute("src");if(!this.isConnected||l===null||!!this._videoSource===this._wantsVideo())break;this._navigateSrc(l);break}case"srcdoc":if(!this.isConnected)break;if(this._pendingPlay=!1,this._abandonComposition("Composition navigated before runtime data was applied"),s!==null)this._pauseForVideoSwitch(),this._teardownVideo(),this.iframe.srcdoc=z(this,s);else{this.iframe.removeAttribute("srcdoc");const l=this.getAttribute("src");l!==null&&this._wantsVideo()&&this._navigateSrc(l)}break;case J:this._applySandboxOriginPolicy(this.isConnected&&i!==s);break;case"width":this._setCompositionSize(Y(s)??1920,this._compositionHeight);break;case"height":this._setCompositionSize(this._compositionWidth,Y(s)??1080);break;case"controls":s!==null?this._setupControls():((n=this.controlsApi)==null||n.destroy(),this.controlsApi=null);break;case"poster":this.posterEl=Pe(this.shadow,s,this.posterEl);break;case"playback-rate":{const l=ie(parseFloat(s||"1"));this._media.updatePlaybackRate(l),this._sendControl("set-playback-rate",{playbackRate:l}),(a=(o=this._directTimelineAdapter)==null?void 0:o.timeScale)==null||a.call(o,l),(c=this.controlsApi)==null||c.updateSpeed(l),this._emit(new Event("ratechange"));break}case"muted":this._handleMutedChange(s);break;case"audio-locked":this._applyAudioLock(s!==null);break;case"volume":{const l=Math.max(0,Math.min(1,parseFloat(s||"1")));this._volume=l,this._syncVideoAudio(),this._media.updateVolume(l),this._sendControl("set-volume",{volume:l}),(p=this.controlsApi)==null||p.updateVolume(l),this._emit(new Event("volumechange"));break}case"audio-src":s?this._media.setupFromUrl(s):this._media.teardownUrlAudio();break;case I:s==="none"&&this.shaderLoader.hideAssetsLoading();break;case te:this._sendControl("set-idle-heartbeat",{slow:s!==null});break;case x:case O:this._applyPlayRange(!0);break;case k:case N:case se:if(!this.isConnected)break;this._reloadShaderOptions();break}}_applySandboxOriginPolicy(e=!1){this.hasAttribute(J)?this.iframe.sandbox.remove("allow-same-origin"):this.iframe.sandbox.add("allow-same-origin"),e&&this._reloadForSandboxOriginPolicy()}_reloadForSandboxOriginPolicy(){if(this._videoSource)return;this._abandonComposition("Sandbox policy changed before runtime data was applied");const e=this.getAttribute("srcdoc");if(e!==null){this.iframe.srcdoc=z(this,e);return}const i=this.getAttribute("src");i===null?this.iframe.src="about:blank":this._loadSrc(i)}get iframeElement(){return this.iframe}get scenes(){return this._scenes}play(){this._play(!0)}_play(e){var o,a;if(this._ready&&!this._assetsReady){this._pendingPlay=!0;return}this._pendingPlay=!1,(o=this.posterEl)==null||o.remove(),this.posterEl=null;const i=this._ready?this._playRange():null;i?De(this._currentTime,i,this._duration,this._runtimeFps)&&(this.seek(i.start),this._enteringRange=!0):this._duration>0&&this._currentTime>=this._duration&&this.seek(0),this._paused=!1;const s=this._tryDirectTimelinePlay();let n=!1;this._sendDisplayScale(),s||(this._sendControl("play"),this._ready&&!this._directTimelineAdapter?this._startParentTickClock():this._ready||(this._pendingPlay=!0,n=!0)),this._media.audioOwner==="parent"?this._media.playAll():this._media.primeAll(),(a=this.controlsApi)==null||a.updatePlaying(!0),!n&&e&&this._emit(new Event("play")),s&&this._directTimelineAdapter&&this._directTimelineClock.start(this._directTimelineAdapter,()=>this._currentTime,()=>this._duration,()=>this._paused,()=>this._clockStop())}pause(){var e;this._pendingPlay=!1,this._tryDirectTimelinePause()?this._showPausedVideoTime():this._sendControl("pause"),this._directTimelineClock.stop(),this._stopParentTickClock(),this._media.audioOwner==="parent"&&this._media.pauseAll(),this._paused=!0,(e=this.controlsApi)==null||e.updatePlaying(!1),this._emit(new Event("pause"))}stopMedia(){this._sendControl("stop-media"),this._stopIframeMedia(),this._media.stopAdoptedMedia()}seek(e){var i,s;this._pendingPlay=!1,!this._trySyncSeek(e)&&!this._tryDirectTimelineSeek(e)&&this._sendControl("seek",{timeSeconds:e,frame:Math.round(e*this._runtimeFps)}),this._directTimelineClock.stop(),this._stopParentTickClock(),this._currentTime=e,this._media.audioOwner==="parent"&&(this._scrubbing?this._media.scrubAll(e):(this._media.pauseAll(),this._media.seekAll(e))),this._paused=!0,(i=this.controlsApi)==null||i.updatePlaying(!1),(s=this.controlsApi)==null||s.updateTime(this._currentTime,this._duration)}setColorGrading(e,i){this._sendControl("set-color-grading",{target:e,grading:i})}clearColorGrading(e){this._sendControl("set-color-grading",{target:e,grading:null})}setColorGradingCompare(e,i){this._sendControl("set-color-grading-compare",{target:e,compare:i})}clearColorGradingCompare(e){this._sendControl("set-color-grading-compare",{target:e,compare:{enabled:!1}})}setRuntimeData(e,i){if(!/^[a-z][a-z0-9-]{0,63}$/.test(e))throw new Error(`Invalid HyperFrames runtime-data channel: ${e}`);if(typeof structuredClone!="function")throw new Error("HyperFrames runtime data requires structuredClone support; refusing an unverified payload");const s=structuredClone(i);this._runtimeData.set(e,s),this._deliverRuntimeData(e,s)}clearRuntimeData(e){if(!/^[a-z][a-z0-9-]{0,63}$/.test(e))throw new Error(`Invalid HyperFrames runtime-data channel: ${e}`);this._runtimeData.delete(e),this._deliverRuntimeDataClear(e)}get currentTime(){return this._currentTime}set currentTime(e){this.seek(e)}get duration(){return this._duration}get compositionWidth(){return this._compositionWidth}get compositionHeight(){return this._compositionHeight}get paused(){return this._paused}get ready(){return this._ready}get assetsReady(){return this._assetsReady}get painted(){return this._painted}get playbackRate(){return ie(parseFloat(this.getAttribute("playback-rate")||"1"))}set playbackRate(e){this.setAttribute("playback-rate",String(ie(e)))}get shaderCaptureScale(){return Kt(this)}set shaderCaptureScale(e){this.setAttribute(k,String(e))}get shaderLoading(){return K(this)}set shaderLoading(e){e==="composition"?this.removeAttribute(N):this.setAttribute(N,e)}get assetsLoadingUi(){return this.getAttribute(I)==="none"?"none":"player"}set assetsLoadingUi(e){e==="none"?this.setAttribute(I,"none"):this.removeAttribute(I)}get muted(){return this.hasAttribute("muted")}set muted(e){e?this.setAttribute("muted",""):this.removeAttribute("muted")}get audioLocked(){return this.hasAttribute("audio-locked")}set audioLocked(e){e?this.setAttribute("audio-locked",""):this.removeAttribute("audio-locked")}_isLockedHostEnvironment(){if(typeof navigator>"u")return!1;const e=navigator.userAgent||"";return/\bClaude\/\d/.test(e)&&/\bElectron\b/.test(e)}_isAudioLocked(){return this.hasAttribute("audio-locked")||this._isLockedHostEnvironment()}_isSlideshowPlayer(){return this.closest("hyperframes-slideshow")!==null}_handleMutedChange(e){var i;if(e===null&&this._isAudioLocked()){this.setAttribute("muted","");return}this._media.updateMuted(e!==null),this._syncVideoAudio(),this._setIframeMediaMuted(e!==null),this._sendControl("set-muted",{muted:e!==null}),(i=this.controlsApi)==null||i.updateMuted(e!==null),this._emit(new Event("volumechange"))}_applyAudioLock(e){var i;e&&(this.muted=!0),(i=this.controlsApi)==null||i.setVolumeControlsHidden(e)}get volume(){return this._volume}set volume(e){this.setAttribute("volume",String(Math.max(0,Math.min(1,e))))}get disableClickToPlay(){return this.hasAttribute(Oe)}set disableClickToPlay(e){this.toggleAttribute(Oe,e)}get loop(){return this.hasAttribute("loop")}set loop(e){e?this.setAttribute("loop",""):this.removeAttribute("loop")}get rangeStart(){return this._readSeconds(x)}set rangeStart(e){this._writeSeconds(x,e)}get rangeEnd(){return this._readSeconds(O)}set rangeEnd(e){this._writeSeconds(O,e)}_readSeconds(e){const i=this.getAttribute(e);return i===null?null:Number(i)}_writeSeconds(e,i){i==null?this.removeAttribute(e):this.setAttribute(e,String(i))}_hasPlayRange(){return this.hasAttribute(x)||this.hasAttribute(O)}_playRange(){return Le(this.rangeStart,this.rangeEnd,this._duration).range}_sendPlayRange(e){const i=(e==null?void 0:e.end)??null;this._sendControl("set-play-range",{startSeconds:(e==null?void 0:e.start)??null,endSeconds:i})}_applyPlayRange(e){const{range:i,clamped:s}=Le(this.rangeStart,this.rangeEnd,this._duration);this._sendPlayRange(i),this._ready&&(this._reportRangeClamp(i,s),i&&e&&!this._pendingPlay&&this._moveIntoPlayRange(i))}_reportRangeClamp(e,i){const s=i?`${this.rangeStart},${this.rangeEnd},${this._duration}`:"";if(s===this._rangeClampReported||(this._rangeClampReported=s,!i))return;const n={rangeStart:(e==null?void 0:e.start)??null,rangeEnd:(e==null?void 0:e.end)??null};this._emit(new CustomEvent("rangeclamped",{detail:{...n,duration:this._duration}}))}_moveIntoPlayRange(e){De(this._currentTime,e,this._duration,this._runtimeFps)&&(this._paused?this.seek(e.start):this._jumpWhilePlaying(e.start))}_jumpWhilePlaying(e){this._directTimelineAdapter?(this._directTimelineAdapter.seek(e,!1),this._currentTime=e):this._runtimeOwnsPlayRange||(this.seek(e),this._enteringRange=!0,this._play(!1))}_clockStop(){const e=this._playRange(),i=(e==null?void 0:e.end)??this._duration;if(!e)return{end:i,shown:i};const s=re(e,this._duration,this._runtimeFps);return{end:i,shown:s<i?(s+i)/2:s}}_sendControl(e,i={}){try{const s=this.iframe.contentWindow;return s?(s.postMessage({...i,source:"hf-parent",type:"control",action:e,...Ye(this._runtimeFps)},"*"),!0):((e==="set-runtime-data"||e==="clear-runtime-data")&&this._rejectRuntimeDataDelivery(i.channel,i.requestId,"Composition iframe is unavailable"),!1)}catch(s){return(e==="set-runtime-data"||e==="clear-runtime-data")&&this._rejectRuntimeDataDelivery(i.channel,i.requestId,s instanceof Error?s.message:String(s)),!1}}_deliverRuntimeData(e,i){if(!this.isConnected||!this._runtimeBridgeReady)return;const s=this._beginRuntimeDataDelivery(e);this._trySetRuntimeDataDirect(e,i,s)||this._sendControl("set-runtime-data",{channel:e,payload:i,requestId:s})}_deliverRuntimeDataClear(e){if(!this.isConnected||!this._runtimeBridgeReady)return;const i=this._beginRuntimeDataDelivery(e);this._tryClearRuntimeDataDirect(e,i)||this._sendControl("clear-runtime-data",{channel:e,requestId:i})}_trySetRuntimeDataDirect(e,i,s){var n;try{const o=(n=this.iframe.contentWindow)==null?void 0:n.__hyperframes;return typeof(o==null?void 0:o.setRuntimeData)!="function"?!1:(o.setRuntimeData(e,i,s),!0)}catch{return!1}}_tryClearRuntimeDataDirect(e,i){var s;try{const n=(s=this.iframe.contentWindow)==null?void 0:s.__hyperframes;return typeof(n==null?void 0:n.clearRuntimeData)!="function"?!1:(n.clearRuntimeData(e,i),!0)}catch{return!1}}_replayRuntimeData(){for(const[e,i]of this._runtimeData)this._deliverRuntimeData(e,i)}_beginRuntimeDataDelivery(e){const i=this._pendingRuntimeData.get(e);i&&window.clearTimeout(i.timeoutId),this._runtimeDataRequestId+=1;const s=this._runtimeDataRequestId,n=window.setTimeout(()=>{this._rejectRuntimeDataDelivery(e,s,`Runtime data delivery timed out after ${xe}ms`)},xe);return this._pendingRuntimeData.set(e,{requestId:s,timeoutId:n}),s}_resolveRuntimeDataDelivery(e,i){const s=this._takeRuntimeDataDelivery(e,i);s&&this._emit(new CustomEvent("runtimedataapplied",{detail:{channel:e,requestId:s.requestId}}))}_rejectRuntimeDataDelivery(e,i,s){const n=this._takeRuntimeDataDelivery(e,i);n&&this._emit(new CustomEvent("runtimedataerror",{detail:{channel:e,requestId:n.requestId,message:typeof s=="string"?s:String(s)}}))}_takeRuntimeDataDelivery(e,i){if(typeof e!="string"||typeof i!="number"||!Number.isSafeInteger(i))return null;const s=this._pendingRuntimeData.get(e);return!s||s.requestId!==i?null:(window.clearTimeout(s.timeoutId),this._pendingRuntimeData.delete(e),s)}_rejectAllRuntimeDataDeliveries(e){for(const[i,s]of[...this._pendingRuntimeData])this._rejectRuntimeDataDelivery(i,s.requestId,e)}_getSameOriginIframeDocument(){try{return this.iframe.contentDocument}catch{return null}}_setIframeMediaMuted(e){const i=this._getSameOriginIframeDocument();if(i)for(const s of i.querySelectorAll("video, audio"))A(s)&&(s.muted=e||s.defaultMuted)}_stopIframeMedia(){const e=this._getSameOriginIframeDocument();if(e)for(const i of e.querySelectorAll("video, audio"))A(i)&&i.pause()}_replayBridgeState(){this._sendControl("set-muted",{muted:this.muted}),this._sendControl("set-volume",{volume:this._volume}),this._sendControl("set-playback-rate",{playbackRate:this.playbackRate}),this._sendControl("set-native-media-sync-disabled",{disabled:this._isSlideshowPlayer()}),this._sendControl("set-web-audio-media-disabled",{disabled:this._isSlideshowPlayer()}),this._sendControl("set-idle-heartbeat",{slow:this.hasAttribute(te)}),this._sendDisplayScale()}_sendDisplayScale(){const e=Xe(this.iframe);e&&this._sendControl("set-display-scale",{scale:e})}_reloadShaderOptions(){if(!this._videoSource){if(this._abandonComposition("Shader options changed before runtime data was applied"),this.hasAttribute("srcdoc")){this.iframe.srcdoc=z(this,this.getAttribute("srcdoc")||"");return}this.hasAttribute("src")&&this._loadSrc(this.getAttribute("src")||"")}}_navigateSrc(e){this._pendingPlay=!1,this._pauseForVideoSwitch(),this._abandonComposition("Composition navigated before runtime data was applied"),this._loadSrc(e)}_wantsVideo(){return ti(this.getAttribute("type"))&&!this.hasAttribute("srcdoc")}_pauseForVideoSwitch(){var e;!this._videoSource&&!this._wantsVideo()||(this._paused=!0,(e=this.controlsApi)==null||e.updatePlaying(!1))}_loadSrc(e){if(this._wantsVideo()){this._loadVideo(e);return}this._teardownVideo(),this.iframe.src=Zt(this,e)}_loadVideo(e){var n,o;this._videoSource||(this._videoSource=ii({onMetadata:a=>this._applyThenEmit(()=>this._onVideoReady(a)),onDurationChange:a=>this._applyTimelineDuration(a.duration),onResize:a=>this._applyVideoSize(a),onPlay:a=>{!a.paused&&this._paused&&this.play()},onPause:a=>{a.paused&&!a.ended&&!this._paused&&this.pause()},onTimeUpdate:()=>{document.hidden&&this._playRange()&&this._directTimelineClock.poll()},onError:(a,c)=>{this._paused||this.pause(),this._emit(new CustomEvent("error",{detail:{message:a,code:c}}))},onPlayRejected:a=>this._onVideoPlayRejected(a)}),this.container.appendChild(this._videoSource.video),this.iframe.hidden=!0,this.iframe.src="about:blank"),this.probe.stop();const{video:i,adapter:s}=this._videoSource;this._directTimelineAdapter=s,this._currentTime=0,this._duration=0,(n=this.controlsApi)==null||n.updateTime(0,0),this._syncVideoAudio(),(o=s.timeScale)==null||o.call(s,this.playbackRate),i.src=e}_teardownVideo(){this._videoSource&&(this._videoSource.destroy(),this._videoSource=null,this.iframe.hidden=!1)}_syncVideoAudio(){this._videoSource&&(this._videoSource.video.muted=this.muted,this._videoSource.video.volume=this._volume)}_onVideoReady(e){this._applyTimelineDuration(e.duration),this._applyVideoSize(e),this._ready=!0,this._dispatchReady(),this._waitForAssetsReady(null),this._afterEvents(()=>{this.hasAttribute("autoplay")&&this._paused&&this.play()})}_applyTimelineDuration(e){var i;!Number.isFinite(e)||e<=0||(this._setDuration(e),(i=this.controlsApi)==null||i.updateTime(this._currentTime,e))}_applyVideoSize(e){e.videoWidth>0&&e.videoHeight>0&&this._setCompositionSize(e.videoWidth,e.videoHeight)}_onVideoPlayRejected(e){e instanceof DOMException&&e.name==="NotAllowedError"&&(this._paused||this.pause(),this._emit(new CustomEvent("playbackerror",{detail:{source:"video",error:e}})))}_trySyncSeek(e){if(this._videoSource)return!1;try{const i=this.iframe.contentWindow,s=i==null?void 0:i.__player;return typeof(s==null?void 0:s.seek)!="function"?!1:(s.seek.call(s,e),!0)}catch{return!1}}_withDirectTimeline(e){const i=this._videoSource?null:this.probe.resolveDirectTimelineAdapter(),s=i||this._directTimelineAdapter;if(!s)return!1;try{return e(s),i&&i!==this._directTimelineAdapter&&this._applyTimelineDuration(i.duration()),this._directTimelineAdapter=s,!0}catch{return!1}}_tryDirectTimelineSeek(e){return this._withDirectTimeline(i=>{i.seek(e,!1),i.pause()})}_tryDirectTimelinePlay(){return this._withDirectTimeline(e=>void e.play())}_tryDirectTimelinePause(){return this._withDirectTimeline(e=>void e.pause())}_showPausedVideoTime(){var e;this._videoSource&&(this._currentTime=this._videoSource.video.currentTime,(e=this.controlsApi)==null||e.updateTime(this._currentTime,this._duration),this._emit(new CustomEvent("timeupdate",{detail:{currentTime:this._currentTime}})))}_startParentTickClock(){this._stopParentTickClock();const e=()=>{if(this._paused){this._parentTickRaf=null;return}this._sendControl("tick"),this._parentTickRaf=requestAnimationFrame(e)};this._parentTickRaf=requestAnimationFrame(e)}_stopParentTickClock(){this._parentTickRaf!==null&&(cancelAnimationFrame(this._parentTickRaf),this._parentTickRaf=null)}_onMessage(e){this._videoSource||this.probe.failed||this._applyThenEmit(()=>this._handleRuntimeMessage(e))}_handleRuntimeMessage(e){$t(e,this.iframe.contentWindow,{getPlaybackState:()=>({currentTime:this._currentTime,duration:this._duration,paused:this._paused,lastUpdateMs:this._lastUpdateMs,enteringRange:this._enteringRange}),setPlaybackState:({currentTime:i,duration:s,paused:n,lastUpdateMs:o,enteringRange:a})=>{this._enteringRange=a===!0,this._currentTime=i,this._setDuration(s),this._paused=n,this._lastUpdateMs=o},getShaderLoadingMode:()=>K(this),shaderLoader:this.shaderLoader,setCompositionSize:(i,s)=>this._setCompositionSize(i,s),sendControl:(i,s)=>this._sendControl(i,s),getIframeDoc:()=>this.iframe.contentDocument,onRuntimeReady:()=>{this._runtimeBridgeReady=!0,this._replayBridgeState(),this._hasPlayRange()&&this._sendPlayRange(this._playRange()),this._replayRuntimeData()},onRuntimeAssetsReady:()=>{this._runtimeAssetsReadyGeneration===this._assetsGeneration&&this._settleAssetsReady(this._assetsGeneration)},onRuntimeDataApplied:(i,s)=>this._resolveRuntimeDataDelivery(i,s),onRuntimeDataError:(i,s,n)=>this._rejectRuntimeDataDelivery(i,s,n),onRuntimeTimelineReady:(i,s)=>this._onRuntimeTimelineReady(i,s),setBuffering:i=>this._setBuffering(i),setRuntimeFps:i=>{this._runtimeFps=i},setRuntimeOwnsPlayRange:i=>{this._runtimeOwnsPlayRange=i},shouldPromoteMediaAutoplayFallback:()=>!this._isSlideshowPlayer(),setScenes:i=>{this._scenes=i,this._emit(new CustomEvent("scenes",{detail:{scenes:i}}))},updateControlsTime:(i,s)=>{var n;return(n=this.controlsApi)==null?void 0:n.updateTime(i,s)},updateControlsPlaying:i=>{var s;return(s=this.controlsApi)==null?void 0:s.updatePlaying(i)},dispatchEvent:i=>this._emit(i),seek:i=>this.seek(i),play:()=>this.play(),getLoop:()=>this.loop,getPlayRange:()=>this._playRange(),media:this._media})}_onRuntimeTimelineReady(e,i){var n;if(this._ready)return;this.probe.stop(),this._setDuration(e),this._directTimelineAdapter=null,this._ready=!0,(n=this.controlsApi)==null||n.updateTime(this._currentTime,e),this._dispatchReady();const s=this._getSameOriginIframeDocument();s&&this._media.setupFromIframe(s),this._replayBridgeState(),this._setIframeMediaMuted(this.muted),this._waitForAssetsReady(s,i),this._playWhenWanted()}_onProbeReady(e){this._applyThenEmit(()=>this._applyProbeResult(e))}_applyProbeResult({duration:e,adapter:i,compositionSize:s}){var o;this._setDuration(e),this._directTimelineAdapter=i.kind==="direct-timeline"?i.timeline:null,s&&this._setCompositionSize(s.width,s.height),this._ready=!0,(o=this.controlsApi)==null||o.updateTime(0,e),this._dispatchReady();const n=this._getSameOriginIframeDocument();n&&this._media.setupFromIframe(n),this._setIframeMediaMuted(this.muted),this._waitForAssetsReady(n),this._playWhenWanted()}_waitForAssetsReady(e,i){this._clearAssetsLoadingShowTimer(),this._assetsReady=!1,this._painted=!1;const s=++this._assetsGeneration;if(!e){i===!1?(this._runtimeAssetsReadyGeneration=s,this._startAssetsLoadingOverlayTimer(s),setTimeout(()=>this._settleAssetsReady(s),Q)):this._settleAssetsReady(s);return}Ke(e,({timedOut:n})=>{s===this._assetsGeneration&&(n&&this._warnStuckAssets(e),this._settleAssetsReady(s))},{timeoutMs:Q}),this._assetsReady||this._startAssetsLoadingOverlayTimer(s)}_startAssetsLoadingOverlayTimer(e){this._assetsLoadingShowTimer=setTimeout(()=>{this._assetsLoadingShowTimer=null,!(e!==this._assetsGeneration||this._assetsReady)&&(this.setAttribute(ee,""),this.assetsLoadingUi!=="none"&&this.shaderLoader.showAssetsLoading())},Ne)}_setBuffering(e){if(e){if(this._bufferingShowTimer!==null||this.hasAttribute(j))return;this._bufferingShowTimer=setTimeout(()=>{this._bufferingShowTimer=null,this.setAttribute(j,""),this.assetsLoadingUi!=="none"&&this.shaderLoader.showAssetsLoading("Buffering","")},Ne);return}this._bufferingShowTimer!==null&&clearTimeout(this._bufferingShowTimer),this._bufferingShowTimer=null,this.hasAttribute(j)&&(this.removeAttribute(j),this.shaderLoader.hideAssetsLoading())}_hasPendingFirstFrameAssets(e){const{pendingMedia:i,pendingImages:s,fontsLoading:n}=Se(e,{scope:Ee});return i.length>0||s.length>0||n}_warnStuckAssets(e){const{pendingMedia:i,pendingImages:s,fontsLoading:n}=Se(e,{scope:Ee}),o=e.defaultView;console.warn(`[hyperframes-player] assets-loading timed out after ${Q}ms, playing anyway`,{stuckMedia:i.map(a=>a.currentSrc||a.getAttribute("src")||`<${a.tagName.toLowerCase()}>`),stuckImages:s.map(a=>a.currentSrc||a.getAttribute("src")||"<img>"),fontsLoading:n,computeReady:(o==null?void 0:o.__renderReady)===!0,documentHidden:e.hidden===!0})}_settleAssetsReady(e){e!==this._assetsGeneration||this._assetsReady||(this._clearAssetsLoadingShowTimer(),this._assetsReady=!0,this.removeAttribute(ee),this.shaderLoader.hideAssetsLoading(),this._emit(new Event("assetsready")),this.shaderLoader.whenHidden(()=>{e===this._assetsGeneration&&(this._painted=!0,this._emit(new Event("painted")))}),this._afterEvents(()=>{this._pendingPlay&&this.play()}))}_abandonComposition(e){this.probe.stop(),this._ready=!1,this._readyDocument=null,this._invalidateAssetsWait(),this._releaseDocument(),this._runtimeBridgeReady=!1,this._rejectAllRuntimeDataDeliveries(e)}_releaseDocument(){this._runtimeOwnsPlayRange=!1,this._enteringRange=!1,this._directTimelineAdapter=null,this._directTimelineClock.stop(),this._stopParentTickClock(),this._setBuffering(!1),this.shaderLoader.reset(),this._media.resetForIframeLoad()}_invalidateAssetsWait(){this._clearAssetsLoadingShowTimer(),this._assetsReady=!1,this._painted=!1,this._assetsGeneration++,this.removeAttribute(ee),this.shaderLoader.hide()}_clearAssetsLoadingShowTimer(){this._assetsLoadingShowTimer!==null&&(clearTimeout(this._assetsLoadingShowTimer),this._assetsLoadingShowTimer=null)}_dispatchReady(){this._readyDocument=this._getSameOriginIframeDocument();const e={duration:this._duration,compositionWidth:this._compositionWidth,compositionHeight:this._compositionHeight};this._emit(new CustomEvent("ready",{detail:e})),this._rescale(),this._rangeClampReported="",this._hasPlayRange()&&this._applyPlayRange(!0)}_setDuration(e){e!==this._duration&&(this._duration=e,this._ready&&(this._emit(new CustomEvent("durationchange",{detail:{duration:e}})),this._hasPlayRange()&&this._applyPlayRange(!1)))}_setCompositionSize(e,i){const s=e!==this._compositionWidth||i!==this._compositionHeight;if(this._compositionWidth=e,this._compositionHeight=i,this.sizer.style.aspectRatio=`${e} / ${i}`,this._rescale(),!s)return;const n={compositionWidth:e,compositionHeight:i};this._emit(new CustomEvent("resize",{detail:n}))}_applyThenEmit(e){if(this._afterUpdate){e();return}const i=[];this._afterUpdate=i;const s=[],n=o=>{try{o()}catch(a){s.push(a)}};n(e);for(const o of i)n(o);if(this._afterUpdate=null,s.length>0)throw s[0]}_afterEvents(e){this._afterUpdate?this._afterUpdate.push(e):e()}_playWhenWanted(){this._afterEvents(()=>{(this.hasAttribute("autoplay")||this._pendingPlay)&&this.play()})}_emit(e){this._afterEvents(()=>this.dispatchEvent(e))}_rescale(){const e=mt(this,this.iframe,this._compositionWidth,this._compositionHeight);e&&this._sendDisplayScale(),!e&&this._ready&&!this._rescaleWarned&&(this._rescaleWarned=!0,console.warn("[hyperframes-player] rescale no-op after ready: zero-size player element",{src:this.getAttribute("src"),offsetWidth:this.offsetWidth,offsetHeight:this.offsetHeight,compositionWidth:this._compositionWidth,compositionHeight:this._compositionHeight}))}_onIframeLoad(){if(!this._connected||this._videoSource)return;const e=this._getSameOriginIframeDocument();if(this._ready&&e===this._readyDocument){e&&this._hasPendingFirstFrameAssets(e)&&this._waitForAssetsReady(e);return}this._ready=!1,this._invalidateAssetsWait(),this._releaseDocument(),this.probe.start()}_setupControls(){this.controlsApi||(this.controlsApi=lt(this.shadow,this.muted,this._volume,this.getAttribute("speed-presets"),{onPlay:()=>this.play(),onPause:()=>this.pause(),onSeek:e=>this.seek(e*this._duration),onScrubStart:()=>{this._scrubbing=!0},onScrubEnd:()=>{this._scrubbing=!1,this.seek(this._currentTime)},onSpeedChange:e=>void(this.playbackRate=e),onMuteToggle:()=>void(this.muted=!this.muted),onVolumeChange:e=>void(this.volume=e)},this._isAudioLocked()),this.controlsApi.updateTime(this._currentTime,this._duration),this.controlsApi.updatePlaying(!this._paused),this.controlsApi.updateSpeed(this.playbackRate))}get _audioOwner(){return this._media.audioOwner}get _parentMedia(){return this._media.entries}_mirrorParentMediaTime(e,i){this._media.mirrorTime(e,i)}_promoteToParentProxy(){let e=null;try{e=this.iframe.contentDocument}catch{}this._media.promoteToParentProxy(e,(i,s)=>this._mirrorParentMediaTime(i,s)),this._sendControl("set-media-output-muted",{muted:!0})}_observeDynamicMedia(e){this._media.setupFromIframe(e)}}customElements.get("hyperframes-player")||customElements.define("hyperframes-player",ni);export{ni as HyperframesPlayer,dt as SPEED_PRESETS,M as formatSpeed,Ce as formatTime};
|