@hyperframes/player 0.6.0-alpha.12 → 0.6.0-alpha.14
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/hyperframes-player.cjs +1 -1
- package/dist/hyperframes-player.cjs.map +1 -1
- package/dist/hyperframes-player.d.cts +11 -0
- package/dist/hyperframes-player.d.ts +11 -0
- package/dist/hyperframes-player.global.js +1 -1
- package/dist/hyperframes-player.global.js.map +1 -1
- package/dist/hyperframes-player.js +1 -1
- package/dist/hyperframes-player.js.map +1 -1
- package/package.json +1 -1
|
@@ -44,6 +44,7 @@ declare class HyperframesPlayer extends HTMLElement {
|
|
|
44
44
|
private _lastUpdateMs;
|
|
45
45
|
private _directTimelineAdapter;
|
|
46
46
|
private _directTimelineRaf;
|
|
47
|
+
private _parentTickRaf;
|
|
47
48
|
/**
|
|
48
49
|
* Parent-frame audio/video proxies, preloaded mirror copies of the iframe's
|
|
49
50
|
* timed media. They exist as a fallback for environments that block iframe
|
|
@@ -194,6 +195,16 @@ declare class HyperframesPlayer extends HTMLElement {
|
|
|
194
195
|
private _tryDirectTimelinePause;
|
|
195
196
|
private _startDirectTimelineClock;
|
|
196
197
|
private _stopDirectTimelineClock;
|
|
198
|
+
/**
|
|
199
|
+
* Widget-frame RAF loop that sends "tick" postMessages to the composition
|
|
200
|
+
* iframe on every frame. Used for the runtime bridge path so that animation
|
|
201
|
+
* advances even when the composition iframe's own rAF is throttled by
|
|
202
|
+
* Chromium (e.g. deeply nested cross-origin iframes in Electron / Claude desktop).
|
|
203
|
+
* The runtime's own rAF loop still runs — ticking GSAP twice per frame is
|
|
204
|
+
* harmless because seekTimelineAndAdapters is idempotent.
|
|
205
|
+
*/
|
|
206
|
+
private _startParentTickClock;
|
|
207
|
+
private _stopParentTickClock;
|
|
197
208
|
private _resolveDirectTimelineAdapter;
|
|
198
209
|
private _resolveDirectTimelineAdapterFromWindow;
|
|
199
210
|
private _hasRuntimeBridge;
|
|
@@ -44,6 +44,7 @@ declare class HyperframesPlayer extends HTMLElement {
|
|
|
44
44
|
private _lastUpdateMs;
|
|
45
45
|
private _directTimelineAdapter;
|
|
46
46
|
private _directTimelineRaf;
|
|
47
|
+
private _parentTickRaf;
|
|
47
48
|
/**
|
|
48
49
|
* Parent-frame audio/video proxies, preloaded mirror copies of the iframe's
|
|
49
50
|
* timed media. They exist as a fallback for environments that block iframe
|
|
@@ -194,6 +195,16 @@ declare class HyperframesPlayer extends HTMLElement {
|
|
|
194
195
|
private _tryDirectTimelinePause;
|
|
195
196
|
private _startDirectTimelineClock;
|
|
196
197
|
private _stopDirectTimelineClock;
|
|
198
|
+
/**
|
|
199
|
+
* Widget-frame RAF loop that sends "tick" postMessages to the composition
|
|
200
|
+
* iframe on every frame. Used for the runtime bridge path so that animation
|
|
201
|
+
* advances even when the composition iframe's own rAF is throttled by
|
|
202
|
+
* Chromium (e.g. deeply nested cross-origin iframes in Electron / Claude desktop).
|
|
203
|
+
* The runtime's own rAF loop still runs — ticking GSAP twice per frame is
|
|
204
|
+
* harmless because seekTimelineAndAdapters is idempotent.
|
|
205
|
+
*/
|
|
206
|
+
private _startParentTickClock;
|
|
207
|
+
private _stopParentTickClock;
|
|
197
208
|
private _resolveDirectTimelineAdapter;
|
|
198
209
|
private _resolveDirectTimelineAdapterFromWindow;
|
|
199
210
|
private _hasRuntimeBridge;
|
|
@@ -415,5 +415,5 @@
|
|
|
415
415
|
background: var(--hfp-accent, #fff);
|
|
416
416
|
pointer-events: none;
|
|
417
417
|
}
|
|
418
|
-
`,U='<svg width="24" height="24" viewBox="0 0 18 18" fill="currentColor"><polygon points="4,2 16,9 4,16"/></svg>',ne='<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>',V='<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>',z='<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>',ae='<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>';var $=[.25,.5,1,1.5,2,4];function x(n){return Number.isInteger(n)?`${n}x`:`${n}x`}function D(n){if(!Number.isFinite(n)||n<0)return"0:00";let e=Math.floor(n),t=Math.floor(e/60),i=e%60;return`${t}:${i.toString().padStart(2,"0")}`}function se(n,e,t={}){let i=t.speedPresets??$,r=document.createElement("div");r.className="hfp-controls",r.addEventListener("click",a=>{a.stopPropagation()});let d=document.createElement("button");d.className="hfp-play-btn",d.type="button",d.innerHTML=U,d.setAttribute("aria-label","Play");let s=document.createElement("div");s.className="hfp-scrubber";let l=document.createElement("div");l.className="hfp-progress",l.style.width="0%",s.appendChild(l);let u=document.createElement("span");u.className="hfp-time",u.textContent="0:00 / 0:00";let h=document.createElement("div");h.className="hfp-speed-wrap";let c=document.createElement("button");c.className="hfp-speed-btn",c.type="button",c.textContent="1x",c.setAttribute("aria-label","Playback speed");let f=document.createElement("div");f.className="hfp-speed-menu",f.setAttribute("role","menu");for(let a of i){let o=document.createElement("button");o.className="hfp-speed-option",o.type="button",o.setAttribute("role","menuitem"),o.dataset.speed=String(a),o.textContent=x(a),a===1&&o.classList.add("hfp-active"),f.appendChild(o)}h.appendChild(f),h.appendChild(c);let E=document.createElement("div");E.className="hfp-volume-wrap";let v=document.createElement("button");v.className="hfp-mute-btn",v.type="button",v.innerHTML=V,v.setAttribute("aria-label","Mute");let g=document.createElement("div");g.className="hfp-volume-slider-wrap";let p=document.createElement("div");p.className="hfp-volume-slider",p.setAttribute("role","slider"),p.setAttribute("aria-label","Volume"),p.setAttribute("aria-valuemin","0"),p.setAttribute("aria-valuemax","100"),p.setAttribute("aria-valuenow","100"),p.tabIndex=0;let b=document.createElement("div");b.className="hfp-volume-fill",b.style.width="100%",p.appendChild(b),g.appendChild(p),E.appendChild(g),E.appendChild(v),r.appendChild(d),r.appendChild(s),r.appendChild(u),r.appendChild(E),r.appendChild(h),n.appendChild(r);let _=!1,S=!1,y=1,M=null,C=i.indexOf(1);C===-1&&(C=0);let k=(a,o)=>a?ae:o===0?z:o<.5?z:V;d.addEventListener("click",a=>{a.stopPropagation(),_?e.onPause():e.onPlay()}),v.addEventListener("click",a=>{a.stopPropagation(),e.onMuteToggle()});let L=!1,P=a=>{let o=p.getBoundingClientRect(),m=Math.max(0,Math.min(1,(a-o.left)/o.width));y=m,b.style.width=`${m*100}%`,p.setAttribute("aria-valuenow",String(Math.round(m*100))),S&&m>0&&e.onMuteToggle(),v.innerHTML=k(S,m),e.onVolumeChange(m)};p.addEventListener("mousedown",a=>{a.stopPropagation(),L=!0,P(a.clientX)});let B=a=>{L&&P(a.clientX)},q=()=>{L=!1};document.addEventListener("mousemove",B),document.addEventListener("mouseup",q),p.addEventListener("touchstart",a=>{L=!0;let o=a.touches[0];o&&P(o.clientX)},{passive:!0});let X=a=>{if(L){let o=a.touches[0];o&&P(o.clientX)}},G=()=>{L=!1};document.addEventListener("touchmove",X,{passive:!0}),document.addEventListener("touchend",G);let Y=.05;p.addEventListener("keydown",a=>{let o=y;if(a.key==="ArrowRight"||a.key==="ArrowUp")o=Math.min(1,y+Y);else if(a.key==="ArrowLeft"||a.key==="ArrowDown")o=Math.max(0,y-Y);else return;a.preventDefault(),a.stopPropagation(),y=o,b.style.width=`${o*100}%`,p.setAttribute("aria-valuenow",String(Math.round(o*100))),S&&o>0&&e.onMuteToggle(),v.innerHTML=k(S,o),e.onVolumeChange(o)});let Q=a=>{for(let o of f.querySelectorAll(".hfp-speed-option"))o.classList.toggle("hfp-active",o.dataset.speed===String(a))};c.addEventListener("click",a=>{a.stopPropagation();let o=f.classList.toggle("hfp-open");c.setAttribute("aria-expanded",String(o))}),f.addEventListener("click",a=>{a.stopPropagation();let o=a.target.closest(".hfp-speed-option");if(!o)return;let m=parseFloat(o.dataset.speed);C=i.indexOf(m),c.textContent=x(m),Q(m),f.classList.remove("hfp-open"),c.setAttribute("aria-expanded","false"),e.onSpeedChange(m)});let J=()=>{f.classList.remove("hfp-open"),c.setAttribute("aria-expanded","false")};document.addEventListener("click",J);let R=a=>{let o=s.getBoundingClientRect(),m=Math.max(0,Math.min(1,(a-o.left)/o.width));e.onSeek(m)},w=!1;s.addEventListener("mousedown",a=>{a.stopPropagation(),w=!0,R(a.clientX)});let Z=a=>{w&&R(a.clientX)},K=()=>{w=!1};document.addEventListener("mousemove",Z),document.addEventListener("mouseup",K),s.addEventListener("touchstart",a=>{w=!0;let o=a.touches[0];o&&R(o.clientX)},{passive:!0});let ee=a=>{if(w){let o=a.touches[0];o&&R(o.clientX)}},te=()=>{w=!1};document.addEventListener("touchmove",ee,{passive:!0}),document.addEventListener("touchend",te);let ie=()=>{M&&clearTimeout(M),M=setTimeout(()=>{_&&r.classList.add("hfp-hidden")},3e3)},re=n instanceof ShadowRoot?n.host:n;return re.addEventListener("mousemove",()=>{r.classList.remove("hfp-hidden"),ie()}),re.addEventListener("mouseleave",()=>{_&&r.classList.add("hfp-hidden")}),{updateTime(a,o){let m=o>0?Math.min(a,o):a,pe=o>0?m/o*100:0;l.style.width=`${pe}%`,u.textContent=`${D(m)} / ${D(o)}`},updatePlaying(a){_=a,d.innerHTML=a?ne:U,d.setAttribute("aria-label",a?"Pause":"Play"),a?ie():r.classList.remove("hfp-hidden")},updateSpeed(a){let o=i.indexOf(a);o!==-1&&(C=o),c.textContent=x(a),Q(a)},updateMuted(a){S=a,v.innerHTML=k(a,y),v.setAttribute("aria-label",a?"Unmute":"Mute")},updateVolume(a){y=a,b.style.width=`${a*100}%`,p.setAttribute("aria-valuenow",String(Math.round(a*100))),v.innerHTML=k(S,a)},show(){r.style.display=""},hide(){r.style.display="none"},destroy(){document.removeEventListener("mousemove",Z),document.removeEventListener("mouseup",K),document.removeEventListener("touchmove",ee),document.removeEventListener("touchend",te),document.removeEventListener("mousemove",B),document.removeEventListener("mouseup",q),document.removeEventListener("touchmove",X),document.removeEventListener("touchend",G),document.removeEventListener("click",J),M&&clearTimeout(M)}}}function oe(n){return n.hasRuntime||n.runtimeInjected?!1:!!(n.hasNestedCompositions||n.hasTimelines&&n.attempts>=5)}var j=null;function ge(){if(j)return j;if(typeof CSSStyleSheet>"u")return null;try{let n=new CSSStyleSheet;return n.replaceSync(F),j=n,n}catch{return null}}var W=30,_e="https://cdn.jsdelivr.net/npm/@hyperframes/core/dist/hyperframe.runtime.iife.js",A="shader-capture-scale",T="shader-loading",ye="__hf_shader_capture_scale",Ee="__hf_shader_loading",H=["Preparing scene transitions","Sampling outgoing scene motion","Sampling incoming scene motion","Caching transition frames","Finalizing transition preview"];function de(n){if(n===null)return null;let e=Number(n);return!Number.isFinite(e)||e<=0?null:String(Math.min(1,Math.max(.25,e)))}function le(n){if(n===null||n.trim()==="")return"composition";let e=n.trim().toLowerCase();return e==="none"||e==="false"||e==="0"||e==="off"?"none":e==="player"||e==="true"||e==="1"||e==="on"?"player":"composition"}function he(n,e,t){t===null?n.delete(e):n.set(e,t)}function Se(n,e,t){let i=n.indexOf("#"),r=i>=0?n.slice(0,i):n,d=i>=0?n.slice(i):"",s=r.indexOf("?"),l=s>=0?r.slice(0,s):r,u=s>=0?r.slice(s+1):"",h=new URLSearchParams(u);he(h,ye,e),he(h,Ee,t==="composition"?null:t);let c=h.toString();return`${l}${c?`?${c}`:""}${d}`}function I(n){return typeof n=="object"&&n!==null}function Le(n){return I(n)&&typeof n.getDuration=="function"}function we(n){return I(n)&&typeof n.duration=="function"&&typeof n.time=="function"&&typeof n.seek=="function"&&typeof n.play=="function"&&typeof n.pause=="function"}function Te(n,e,t){if(e===null&&t==="composition")return n;let i=[];e!==null&&i.push(`window.__HF_SHADER_CAPTURE_SCALE=${JSON.stringify(e)};`),t!=="composition"&&i.push(`window.__HF_SHADER_LOADING=${JSON.stringify(t)};`);let r=`<script data-hyperframes-player-shader-options>${i.join("")}</script>`;return/<head\b[^>]*>/i.test(n)?n.replace(/<head\b[^>]*>/i,d=>`${d}${r}`):/<html\b[^>]*>/i.test(n)?n.replace(/<html\b[^>]*>/i,d=>`${d}${r}`):`${r}${n}`}var O=class n extends HTMLElement{static get observedAttributes(){return["src","srcdoc","width","height","controls","muted","volume","poster","playback-rate","audio-src",A,T]}shadow;container;iframe;posterEl=null;controlsApi=null;resizeObserver;shaderLoaderEl;shaderLoaderFillEl;shaderLoaderTitleEl;shaderLoaderDetailEl;shaderLoaderTransitionValueEl;shaderLoaderFrameLabelEl;shaderLoaderFrameValueEl;shaderLoaderFrameRowEl;shaderLoaderHideTimeout=null;_ready=!1;_duration=0;_currentTime=0;_paused=!0;_volume=1;_compositionWidth=1920;_compositionHeight=1080;_probeInterval=null;_lastUpdateMs=0;_directTimelineAdapter=null;_directTimelineRaf=null;_parentMedia=[];_audioOwner="runtime";_mediaObserver;_playbackErrorPosted=!1;constructor(){super(),this.shadow=this.attachShadow({mode:"open"});let e=ge();if(e)this.shadow.adoptedStyleSheets=[e];else{let i=document.createElement("style");i.textContent=F,this.shadow.appendChild(i)}this.container=document.createElement("div"),this.container.className="hfp-container",this.iframe=document.createElement("iframe"),this.iframe.className="hfp-iframe",this.iframe.sandbox.add("allow-scripts","allow-same-origin"),this.iframe.allow="autoplay; fullscreen",this.iframe.referrerPolicy="no-referrer",this.iframe.title="HyperFrames Composition",this.container.appendChild(this.iframe),this.shadow.appendChild(this.container);let t=this._createShaderLoader();this.shaderLoaderEl=t.root,this.shaderLoaderFillEl=t.fill,this.shaderLoaderTitleEl=t.title,this.shaderLoaderDetailEl=t.detail,this.shaderLoaderTransitionValueEl=t.transitionValue,this.shaderLoaderFrameLabelEl=t.frameLabel,this.shaderLoaderFrameValueEl=t.frameValue,this.shaderLoaderFrameRowEl=t.frameRow,this.shadow.appendChild(this.shaderLoaderEl),this.addEventListener("click",i=>{this._isControlsClick(i)||(this._paused?this.play():this.pause())}),this.resizeObserver=new ResizeObserver(()=>this._updateScale()),this._onMessage=this._onMessage.bind(this),this._onIframeLoad=this._onIframeLoad.bind(this)}connectedCallback(){this.resizeObserver.observe(this),window.addEventListener("message",this._onMessage),this.iframe.addEventListener("load",this._onIframeLoad),this.hasAttribute("controls")&&this._setupControls(),this.hasAttribute("poster")&&this._setupPoster(),this.hasAttribute("audio-src")&&this._setupParentAudioFromUrl(this.getAttribute("audio-src")),this.hasAttribute("srcdoc")&&(this.iframe.srcdoc=this._prepareSrcdoc(this.getAttribute("srcdoc"))),this.hasAttribute("src")&&(this.iframe.src=this._prepareSrc(this.getAttribute("src")))}disconnectedCallback(){this.resizeObserver.disconnect(),window.removeEventListener("message",this._onMessage),this.iframe.removeEventListener("load",this._onIframeLoad),this._probeInterval&&clearInterval(this._probeInterval),this._stopDirectTimelineClock(),this._directTimelineAdapter=null,this.shaderLoaderHideTimeout&&clearTimeout(this.shaderLoaderHideTimeout),this.shaderLoaderHideTimeout=null,this._teardownMediaObserver(),this.controlsApi?.destroy();for(let e of this._parentMedia)e.el.pause(),e.el.src="";this._parentMedia=[]}attributeChangedCallback(e,t,i){switch(e){case"src":i&&(this._ready=!1,this.iframe.src=this._prepareSrc(i));break;case"srcdoc":this._ready=!1,i!==null?this.iframe.srcdoc=this._prepareSrcdoc(i):this.iframe.removeAttribute("srcdoc");break;case"width":this._compositionWidth=parseInt(i||"1920",10),this._updateScale();break;case"height":this._compositionHeight=parseInt(i||"1080",10),this._updateScale();break;case"controls":i!==null?this._setupControls():(this.controlsApi?.destroy(),this.controlsApi=null);break;case"poster":this._setupPoster();break;case"playback-rate":{let r=parseFloat(i||"1");for(let d of this._parentMedia)d.el.playbackRate=r;this._sendControl("set-playback-rate",{playbackRate:r}),this.controlsApi?.updateSpeed(r),this.dispatchEvent(new Event("ratechange"));break}case"muted":for(let r of this._parentMedia)r.el.muted=i!==null;this._sendControl("set-muted",{muted:i!==null}),this.controlsApi?.updateMuted(i!==null),this.dispatchEvent(new Event("volumechange"));break;case"volume":{let r=Math.max(0,Math.min(1,parseFloat(i||"1")));this._volume=r;for(let d of this._parentMedia)d.el.volume=r;this._sendControl("set-volume",{volume:r}),this.controlsApi?.updateVolume(r),this.dispatchEvent(new Event("volumechange"));break}case"audio-src":i&&this._setupParentAudioFromUrl(i);break;case A:case T:this._reloadShaderOptions();break}}get iframeElement(){return this.iframe}play(){this._hidePoster(),this._duration>0&&this._currentTime>=this._duration&&this.seek(0);let e=this._tryDirectTimelinePlay();e||this._sendControl("play"),this._audioOwner==="parent"&&this._playParentMedia(),this._paused=!1,this.controlsApi?.updatePlaying(!0),this.dispatchEvent(new Event("play")),e&&this._startDirectTimelineClock()}pause(){this._tryDirectTimelinePause()||this._sendControl("pause"),this._stopDirectTimelineClock(),this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=!0,this.controlsApi?.updatePlaying(!1),this.dispatchEvent(new Event("pause"))}seek(e){if(!this._trySyncSeek(e)&&!this._tryDirectTimelineSeek(e)){let t=Math.round(e*W);this._sendControl("seek",{frame:t})}if(this._stopDirectTimelineClock(),this._currentTime=e,this._audioOwner==="parent")for(let t of this._parentMedia){let i=e-t.start;i>=0&&i<t.duration&&(t.el.currentTime=i)}this._paused=!0,this.controlsApi?.updatePlaying(!1),this.controlsApi?.updateTime(this._currentTime,this._duration)}get currentTime(){return this._currentTime}set currentTime(e){this.seek(e)}get duration(){return this._duration}get paused(){return this._paused}get ready(){return this._ready}get playbackRate(){return parseFloat(this.getAttribute("playback-rate")||"1")}set playbackRate(e){this.setAttribute("playback-rate",String(e))}get shaderCaptureScale(){return Number(de(this.getAttribute(A))??"1")}set shaderCaptureScale(e){this.setAttribute(A,String(e))}get shaderLoading(){return le(this.getAttribute(T))}set shaderLoading(e){e==="composition"?this.removeAttribute(T):this.setAttribute(T,e)}get muted(){return this.hasAttribute("muted")}set muted(e){e?this.setAttribute("muted",""):this.removeAttribute("muted")}get volume(){return this._volume}set volume(e){this.setAttribute("volume",String(Math.max(0,Math.min(1,e))))}get loop(){return this.hasAttribute("loop")}set loop(e){e?this.setAttribute("loop",""):this.removeAttribute("loop")}_sendControl(e,t={}){try{this.iframe.contentWindow?.postMessage({source:"hf-parent",type:"control",action:e,...t},"*")}catch{}}_shaderCaptureScaleParam(){return de(this.getAttribute(A))}_shaderLoadingMode(){return le(this.getAttribute(T))}_prepareSrc(e){return Se(e,this._shaderCaptureScaleParam(),this._shaderLoadingMode())}_prepareSrcdoc(e){return Te(e,this._shaderCaptureScaleParam(),this._shaderLoadingMode())}_reloadShaderOptions(){if(this._shaderLoadingMode()!=="player"&&this._resetShaderLoader(),this.hasAttribute("srcdoc")){this.iframe.srcdoc=this._prepareSrcdoc(this.getAttribute("srcdoc")||"");return}this.hasAttribute("src")&&(this.iframe.src=this._prepareSrc(this.getAttribute("src")||""))}_createShaderLoader(){let e=document.createElement("div");e.className="hfp-shader-loader",e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.setAttribute("aria-label","Preparing scene transitions"),e.setAttribute("data-hyperframes-ignore",""),e.draggable=!1;let t=g=>{g.preventDefault(),g.stopPropagation()};for(let g of["selectstart","dragstart","pointerdown","mousedown","click","dblclick","contextmenu","touchstart"])e.addEventListener(g,t,{capture:!0});let i=document.createElement("div");i.className="hfp-shader-loader-panel",i.draggable=!1;let r=document.createElement("div");r.className="hfp-shader-loader-mark",r.draggable=!1,r.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("");let d=document.createElement("div");d.className="hfp-shader-loader-title";let s=document.createElement("span");s.className="hfp-shader-loader-title-text",s.textContent=H[0]||"Preparing scene transitions",d.appendChild(s);let l=document.createElement("div");l.className="hfp-shader-loader-detail",l.textContent="Rendering animated scene samples for shader transitions.";let u=document.createElement("div");u.className="hfp-shader-loader-track",u.setAttribute("aria-hidden","true");let h=document.createElement("div");h.className="hfp-shader-loader-fill",u.appendChild(h);let c=document.createElement("div");c.className="hfp-shader-loader-progress";let f=g=>{let p=document.createElement("div");p.className="hfp-shader-loader-row";let b=document.createElement("span");b.className="hfp-shader-loader-label",b.textContent=g;let _=document.createElement("span");return _.className="hfp-shader-loader-value",p.appendChild(b),p.appendChild(_),c.appendChild(p),{row:p,label:b,value:_}},E=f("transition"),v=f("transition frame");return i.appendChild(r),i.appendChild(d),i.appendChild(l),i.appendChild(u),i.appendChild(c),e.appendChild(i),{root:e,fill:h,title:s,detail:l,transitionValue:E.value,frameLabel:v.label,frameValue:v.value,frameRow:v.row}}_showShaderLoader(){this.shaderLoaderHideTimeout&&(clearTimeout(this.shaderLoaderHideTimeout),this.shaderLoaderHideTimeout=null),this.shaderLoaderEl.classList.remove("hfp-hiding"),this.shaderLoaderEl.classList.add("hfp-visible")}_hideShaderLoader(){if(this.shaderLoaderEl.classList.contains("hfp-hiding")){this.shaderLoaderHideTimeout||this._scheduleShaderLoaderHideCleanup();return}this.shaderLoaderEl.classList.contains("hfp-visible")&&(this.shaderLoaderEl.classList.add("hfp-hiding"),this.shaderLoaderEl.classList.remove("hfp-visible"),this._scheduleShaderLoaderHideCleanup())}_scheduleShaderLoaderHideCleanup(){this.shaderLoaderHideTimeout&&clearTimeout(this.shaderLoaderHideTimeout),this.shaderLoaderHideTimeout=setTimeout(()=>{this.shaderLoaderEl.classList.remove("hfp-hiding"),this.shaderLoaderHideTimeout=null},420)}_resetShaderLoader(){this.shaderLoaderHideTimeout&&(clearTimeout(this.shaderLoaderHideTimeout),this.shaderLoaderHideTimeout=null),this.shaderLoaderEl.classList.remove("hfp-visible","hfp-hiding"),this.shaderLoaderFillEl.style.transform="scaleX(0)",this.shaderLoaderTransitionValueEl.textContent="",this.shaderLoaderFrameValueEl.textContent="",this.shaderLoaderFrameRowEl.style.visibility="hidden"}_updateShaderLoader(e){if(this._shaderLoadingMode()!=="player"){this._resetShaderLoader();return}if(e.ready||!e.loading){this._hideShaderLoader();return}let t=typeof e.progress=="number"&&Number.isFinite(e.progress)?e.progress:0,i=typeof e.total=="number"&&Number.isFinite(e.total)?e.total:0,r=i>0?Math.min(1,Math.max(0,t/i)):0,d=Math.min(H.length-1,Math.floor(r*H.length));this.shaderLoaderTitleEl.textContent=H[d]||"Preparing scene transitions",this.shaderLoaderDetailEl.textContent=e.phase==="cached"?"Loading cached transition frames before playback.":e.phase==="finalizing"?"Uploading transition textures for smooth playback.":"Rendering animated scene samples for shader transitions.",this.shaderLoaderFillEl.style.transform=`scaleX(${r})`,this.shaderLoaderTransitionValueEl.textContent=e.currentTransition!==void 0&&e.transitionTotal!==void 0?`${e.currentTransition}/${e.transitionTotal}`:i>0?`${t}/${i}`:"";let s=e.transitionFrame!==void 0&&e.transitionFrames!==void 0?`${e.transitionFrame}/${e.transitionFrames}`:"";this.shaderLoaderFrameLabelEl.textContent=e.phase==="cached"?"cached transition frames":e.phase==="finalizing"?"finalizing transition frames":"rendering transition frames",this.shaderLoaderFrameValueEl.textContent=s,this.shaderLoaderFrameRowEl.style.visibility=s?"visible":"hidden",this.shaderLoaderEl.setAttribute("aria-valuenow",String(Math.round(r*100))),this._showShaderLoader()}_trySyncSeek(e){try{let i=this.iframe.contentWindow?.__player,r=i?.seek;return typeof r!="function"?!1:(r.call(i,e),!0)}catch{return!1}}_tryDirectTimelineSeek(e){let t=this._directTimelineAdapter||this._resolveDirectTimelineAdapter();if(!t)return!1;try{return t.seek(e),t.pause(),this._directTimelineAdapter=t,!0}catch{return!1}}_tryDirectTimelinePlay(){let e=this._directTimelineAdapter||this._resolveDirectTimelineAdapter();if(!e)return!1;try{return e.play(),this._directTimelineAdapter=e,!0}catch{return!1}}_tryDirectTimelinePause(){let e=this._directTimelineAdapter||this._resolveDirectTimelineAdapter();if(!e)return!1;try{return e.pause(),this._directTimelineAdapter=e,!0}catch{return!1}}_startDirectTimelineClock(){this._stopDirectTimelineClock();let e=()=>{let t=this._directTimelineAdapter;if(!t||this._paused){this._directTimelineRaf=null;return}let i;try{i=t.time()}catch{this._directTimelineRaf=null;return}this._duration>0&&(i=Math.min(i,this._duration)),this._currentTime=i;let r=this._duration>0&&i>=this._duration,d=performance.now();if((d-this._lastUpdateMs>100||r)&&(this._lastUpdateMs=d,this.controlsApi?.updateTime(this._currentTime,this._duration),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:this._currentTime}}))),r){if(this.loop){this.seek(0),this.play();return}t.pause(),this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=!0,this.controlsApi?.updatePlaying(!1),this.dispatchEvent(new Event("ended")),this._directTimelineRaf=null;return}this._directTimelineRaf=requestAnimationFrame(e)};this._directTimelineRaf=requestAnimationFrame(e)}_stopDirectTimelineClock(){this._directTimelineRaf!==null&&(cancelAnimationFrame(this._directTimelineRaf),this._directTimelineRaf=null)}_resolveDirectTimelineAdapter(){try{let e=this.iframe.contentWindow;return e?this._resolveDirectTimelineAdapterFromWindow(e):null}catch{return null}}_resolveDirectTimelineAdapterFromWindow(e){if(this._hasRuntimeBridge(e))return null;let t=Reflect.get(e,"__timelines");if(!I(t))return null;let i=Object.keys(t);if(i.length===0)return null;let r=this.iframe.contentDocument?.querySelector("[data-composition-id]")?.getAttribute("data-composition-id"),d=r&&r in t?r:i[i.length-1],s=t[d];return we(s)?s:null}_hasRuntimeBridge(e){return Reflect.get(e,"__hf")!==void 0||I(Reflect.get(e,"__player"))}_resolvePlaybackDurationAdapter(e){let t=Reflect.get(e,"__player");if(Le(t))return{kind:"runtime",getDuration:()=>t.getDuration()};let i=this._resolveDirectTimelineAdapterFromWindow(e);return i?{kind:"direct-timeline",timeline:i,getDuration:()=>i.duration()}:null}_isControlsClick(e){return e.composedPath().some(t=>t instanceof HTMLElement&&t.classList.contains("hfp-controls"))}_onMessage(e){if(e.source!==this.iframe.contentWindow)return;let t=e.data;if(!(!t||t.source!=="hf-preview")){if(t.type==="shader-transition-state"){let i=t.state&&typeof t.state=="object"?t.state:{};this._updateShaderLoader(i),this.dispatchEvent(new CustomEvent("shadertransitionstate",{detail:{compositionId:t.compositionId,state:i}}));return}if(t.type==="state"){let i=(t.frame??0)/W;this._currentTime=this._duration>0?Math.min(i,this._duration):i;let r=!this._paused,d=!t.isPlaying,s=this._duration>0&&this._currentTime>=this._duration&&(r||t.isPlaying);if(s&&this.loop){this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=d,this.seek(0),this.play();return}this._paused=d,this._audioOwner==="parent"&&(r&&this._paused?this._pauseParentMedia():!r&&!this._paused&&this._playParentMedia(),this._mirrorParentMediaTime(this._currentTime));let l=performance.now();(l-this._lastUpdateMs>100||this._paused!==r)&&(this._lastUpdateMs=l,this.controlsApi?.updateTime(this._currentTime,this._duration),this.controlsApi?.updatePlaying(!this._paused),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:this._currentTime}}))),s&&(this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=!0,this.controlsApi?.updatePlaying(!1),this.dispatchEvent(new Event("ended")))}t.type==="media-autoplay-blocked"&&this._promoteToParentProxy(),t.type==="timeline"&&t.durationInFrames>0&&Number.isFinite(t.durationInFrames)&&(this._duration=t.durationInFrames/W,this.controlsApi?.updateTime(this._currentTime,this._duration)),t.type==="stage-size"&&t.width>0&&t.height>0&&(this._compositionWidth=t.width,this._compositionHeight=t.height,this._updateScale())}}_runtimeInjected=!1;_onIframeLoad(){let e=0;this._runtimeInjected=!1,this._directTimelineAdapter=null,this._stopDirectTimelineClock(),this._resetShaderLoader();let t=this._audioOwner==="parent";this._audioOwner="runtime",this._playbackErrorPosted=!1,this._pauseParentMedia(),this._teardownMediaObserver(),t&&this.dispatchEvent(new CustomEvent("audioownershipchange",{detail:{owner:"runtime",reason:"iframe-reload"}})),this._probeInterval&&clearInterval(this._probeInterval),this._probeInterval=setInterval(()=>{e++;try{let i=this.iframe.contentWindow;if(!i)return;let r=!!(i.__hf||i.__player),d=!!(i.__timelines&&Object.keys(i.__timelines).length>0),s=!!this.iframe.contentDocument?.querySelector("[data-composition-src]");if(oe({hasRuntime:r,hasTimelines:d,hasNestedCompositions:s,runtimeInjected:this._runtimeInjected,attempts:e})){this._injectRuntime();return}if(this._runtimeInjected&&!r)return;let l=this._resolvePlaybackDurationAdapter(i);if(l&&l.getDuration()>0){clearInterval(this._probeInterval),this._duration=l.getDuration(),this._directTimelineAdapter=l.kind==="direct-timeline"?l.timeline:null,this._ready=!0,this.controlsApi?.updateTime(0,this._duration),this.dispatchEvent(new CustomEvent("ready",{detail:{duration:this._duration}}));let h=this.iframe.contentDocument?.querySelector("[data-composition-id]");if(h){let c=parseInt(h.getAttribute("data-width")||"0",10),f=parseInt(h.getAttribute("data-height")||"0",10);c>0&&f>0&&(this._compositionWidth=c,this._compositionHeight=f,this._updateScale())}this._setupParentMedia(),this.hasAttribute("autoplay")&&this.play();return}}catch{}e>=40&&(clearInterval(this._probeInterval),this.dispatchEvent(new CustomEvent("error",{detail:{message:"Composition timeline not found after 8s"}})))},200)}_injectRuntime(){this._runtimeInjected=!0;try{let e=this.iframe.contentDocument;if(!e)return;let t=e.createElement("script");t.src=_e,t.onload=()=>{},t.onerror=()=>{},(e.head||e.documentElement).appendChild(t)}catch{}}_updateScale(){let e=this.getBoundingClientRect();if(e.width===0||e.height===0)return;let t=Math.min(e.width/this._compositionWidth,e.height/this._compositionHeight);this.iframe.style.width=`${this._compositionWidth}px`,this.iframe.style.height=`${this._compositionHeight}px`,this.iframe.style.transform=`translate(-50%, -50%) scale(${t})`}_setupControls(){if(this.controlsApi)return;let e={onPlay:()=>this.play(),onPause:()=>this.pause(),onSeek:r=>this.seek(r*this._duration),onSpeedChange:r=>{this.playbackRate=r},onMuteToggle:()=>{this.muted=!this.muted},onVolumeChange:r=>{this.volume=r}},t=this.getAttribute("speed-presets"),i=t?t.split(",").map(Number).filter(r=>!isNaN(r)&&r>0):void 0;this.controlsApi=se(this.shadow,e,{speedPresets:i}),this.controlsApi.updateMuted(this.muted),this.controlsApi.updateVolume(this._volume)}_setupPoster(){let e=this.getAttribute("poster");if(!e){this.posterEl?.remove(),this.posterEl=null;return}this.posterEl||(this.posterEl=document.createElement("img"),this.posterEl.className="hfp-poster",this.shadow.appendChild(this.posterEl)),this.posterEl.src=e}_playParentMedia(){for(let e of this._parentMedia)e.el.src&&e.el.play().catch(t=>this._reportPlaybackError(t))}_reportPlaybackError(e){this._playbackErrorPosted||(this._playbackErrorPosted=!0,this.dispatchEvent(new CustomEvent("playbackerror",{detail:{source:"parent-proxy",error:e}})))}_pauseParentMedia(){for(let e of this._parentMedia)e.el.pause()}static MIRROR_DRIFT_THRESHOLD_SECONDS=.05;static MIRROR_REQUIRED_CONSECUTIVE_DRIFT_SAMPLES=2;_mirrorParentMediaTime(e,t){let i=t?.force===!0,r=n.MIRROR_REQUIRED_CONSECUTIVE_DRIFT_SAMPLES,d=n.MIRROR_DRIFT_THRESHOLD_SECONDS;for(let s of this._parentMedia){let l=e-s.start;if(l<0||l>=s.duration){s.driftSamples=0;continue}Math.abs(s.el.currentTime-l)>d?(s.driftSamples+=1,(i||s.driftSamples>=r)&&(s.el.currentTime=l,s.driftSamples=0)):s.driftSamples=0}}_promoteToParentProxy(){this._audioOwner!=="parent"&&(this._audioOwner="parent",this._sendControl("set-media-output-muted",{muted:!0}),this._mirrorParentMediaTime(this._currentTime,{force:!0}),this._paused||this._playParentMedia(),this.dispatchEvent(new CustomEvent("audioownershipchange",{detail:{owner:"parent",reason:"autoplay-blocked"}})))}_createParentMedia(e,t,i,r){if(this._parentMedia.some(l=>l.el.src===e))return null;let d=t==="video"?document.createElement("video"):new Audio;d.preload="auto",d.src=e,d.load(),d.muted=this.muted,d.volume=this._volume,this.playbackRate!==1&&(d.playbackRate=this.playbackRate);let s={el:d,start:i,duration:r,driftSamples:0};return this._parentMedia.push(s),s}_setupParentAudioFromUrl(e){this._createParentMedia(e,"audio",0,1/0)}_setupParentMedia(){try{let e=this.iframe.contentDocument;if(!e)return;let t=e.querySelectorAll("audio[data-start], video[data-start]");for(let i of t)this._adoptIframeMedia(i);this._observeDynamicMedia(e)}catch{}}_adoptIframeMedia(e){let t=e.getAttribute("src")||e.querySelector("source")?.getAttribute("src");if(!t)return;let i=new URL(t,e.ownerDocument.baseURI).href,r=parseFloat(e.getAttribute("data-start")||"0"),d=parseFloat(e.getAttribute("data-duration")||"Infinity"),s=e.tagName==="VIDEO"?"video":"audio",l=this._createParentMedia(i,s,r,d);l&&this._audioOwner==="parent"&&(this._mirrorParentMediaTime(this._currentTime,{force:!0}),!this._paused&&l.el.src&&l.el.play().catch(u=>this._reportPlaybackError(u)))}_observeDynamicMedia(e){if(this._teardownMediaObserver(),typeof MutationObserver>"u"||!e.body)return;let t=new MutationObserver(r=>{for(let d of r){for(let s of d.addedNodes){if(!(s instanceof Element))continue;let l=[];s.matches?.("audio[data-start], video[data-start]")&&l.push(s);let u=s.querySelectorAll?.("audio[data-start], video[data-start]");if(u)for(let h of u)l.push(h);for(let h of l)this._adoptIframeMedia(h)}for(let s of d.removedNodes){if(!(s instanceof Element))continue;let l=[];s.matches?.("audio[data-start], video[data-start]")&&l.push(s);let u=s.querySelectorAll?.("audio[data-start], video[data-start]");if(u)for(let h of u)l.push(h);for(let h of l)this._detachIframeMedia(h)}}}),i=e.querySelectorAll("[data-composition-id]");if(i.length>0)for(let r of i)t.observe(r,{childList:!0,subtree:!0});else t.observe(e.body,{childList:!0,subtree:!0});this._mediaObserver=t}_teardownMediaObserver(){this._mediaObserver?.disconnect(),this._mediaObserver=void 0}_detachIframeMedia(e){let t=e.getAttribute("src")||e.querySelector("source")?.getAttribute("src");if(!t)return;let i=new URL(t,e.ownerDocument.baseURI).href,r=this._parentMedia.findIndex(s=>s.el.src===i);if(r===-1)return;let d=this._parentMedia[r];d.el.pause(),d.el.src="",this._parentMedia.splice(r,1)}_hidePoster(){this.posterEl?.remove(),this.posterEl=null}};customElements.get("hyperframes-player")||customElements.define("hyperframes-player",O);return be(Me);})();
|
|
418
|
+
`,U='<svg width="24" height="24" viewBox="0 0 18 18" fill="currentColor"><polygon points="4,2 16,9 4,16"/></svg>',ne='<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>',V='<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>',z='<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>',ae='<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>';var $=[.25,.5,1,1.5,2,4];function x(n){return Number.isInteger(n)?`${n}x`:`${n}x`}function D(n){if(!Number.isFinite(n)||n<0)return"0:00";let e=Math.floor(n),t=Math.floor(e/60),i=e%60;return`${t}:${i.toString().padStart(2,"0")}`}function se(n,e,t={}){let i=t.speedPresets??$,r=document.createElement("div");r.className="hfp-controls",r.addEventListener("click",a=>{a.stopPropagation()});let d=document.createElement("button");d.className="hfp-play-btn",d.type="button",d.innerHTML=U,d.setAttribute("aria-label","Play");let s=document.createElement("div");s.className="hfp-scrubber";let l=document.createElement("div");l.className="hfp-progress",l.style.width="0%",s.appendChild(l);let u=document.createElement("span");u.className="hfp-time",u.textContent="0:00 / 0:00";let h=document.createElement("div");h.className="hfp-speed-wrap";let c=document.createElement("button");c.className="hfp-speed-btn",c.type="button",c.textContent="1x",c.setAttribute("aria-label","Playback speed");let f=document.createElement("div");f.className="hfp-speed-menu",f.setAttribute("role","menu");for(let a of i){let o=document.createElement("button");o.className="hfp-speed-option",o.type="button",o.setAttribute("role","menuitem"),o.dataset.speed=String(a),o.textContent=x(a),a===1&&o.classList.add("hfp-active"),f.appendChild(o)}h.appendChild(f),h.appendChild(c);let E=document.createElement("div");E.className="hfp-volume-wrap";let v=document.createElement("button");v.className="hfp-mute-btn",v.type="button",v.innerHTML=V,v.setAttribute("aria-label","Mute");let g=document.createElement("div");g.className="hfp-volume-slider-wrap";let p=document.createElement("div");p.className="hfp-volume-slider",p.setAttribute("role","slider"),p.setAttribute("aria-label","Volume"),p.setAttribute("aria-valuemin","0"),p.setAttribute("aria-valuemax","100"),p.setAttribute("aria-valuenow","100"),p.tabIndex=0;let b=document.createElement("div");b.className="hfp-volume-fill",b.style.width="100%",p.appendChild(b),g.appendChild(p),E.appendChild(g),E.appendChild(v),r.appendChild(d),r.appendChild(s),r.appendChild(u),r.appendChild(E),r.appendChild(h),n.appendChild(r);let _=!1,S=!1,y=1,M=null,k=i.indexOf(1);k===-1&&(k=0);let A=(a,o)=>a?ae:o===0?z:o<.5?z:V;d.addEventListener("click",a=>{a.stopPropagation(),_?e.onPause():e.onPlay()}),v.addEventListener("click",a=>{a.stopPropagation(),e.onMuteToggle()});let L=!1,P=a=>{let o=p.getBoundingClientRect(),m=Math.max(0,Math.min(1,(a-o.left)/o.width));y=m,b.style.width=`${m*100}%`,p.setAttribute("aria-valuenow",String(Math.round(m*100))),S&&m>0&&e.onMuteToggle(),v.innerHTML=A(S,m),e.onVolumeChange(m)};p.addEventListener("mousedown",a=>{a.stopPropagation(),L=!0,P(a.clientX)});let q=a=>{L&&P(a.clientX)},B=()=>{L=!1};document.addEventListener("mousemove",q),document.addEventListener("mouseup",B),p.addEventListener("touchstart",a=>{L=!0;let o=a.touches[0];o&&P(o.clientX)},{passive:!0});let X=a=>{if(L){let o=a.touches[0];o&&P(o.clientX)}},G=()=>{L=!1};document.addEventListener("touchmove",X,{passive:!0}),document.addEventListener("touchend",G);let Y=.05;p.addEventListener("keydown",a=>{let o=y;if(a.key==="ArrowRight"||a.key==="ArrowUp")o=Math.min(1,y+Y);else if(a.key==="ArrowLeft"||a.key==="ArrowDown")o=Math.max(0,y-Y);else return;a.preventDefault(),a.stopPropagation(),y=o,b.style.width=`${o*100}%`,p.setAttribute("aria-valuenow",String(Math.round(o*100))),S&&o>0&&e.onMuteToggle(),v.innerHTML=A(S,o),e.onVolumeChange(o)});let Q=a=>{for(let o of f.querySelectorAll(".hfp-speed-option"))o.classList.toggle("hfp-active",o.dataset.speed===String(a))};c.addEventListener("click",a=>{a.stopPropagation();let o=f.classList.toggle("hfp-open");c.setAttribute("aria-expanded",String(o))}),f.addEventListener("click",a=>{a.stopPropagation();let o=a.target.closest(".hfp-speed-option");if(!o)return;let m=parseFloat(o.dataset.speed);k=i.indexOf(m),c.textContent=x(m),Q(m),f.classList.remove("hfp-open"),c.setAttribute("aria-expanded","false"),e.onSpeedChange(m)});let J=()=>{f.classList.remove("hfp-open"),c.setAttribute("aria-expanded","false")};document.addEventListener("click",J);let R=a=>{let o=s.getBoundingClientRect(),m=Math.max(0,Math.min(1,(a-o.left)/o.width));e.onSeek(m)},T=!1;s.addEventListener("mousedown",a=>{a.stopPropagation(),T=!0,R(a.clientX)});let Z=a=>{T&&R(a.clientX)},K=()=>{T=!1};document.addEventListener("mousemove",Z),document.addEventListener("mouseup",K),s.addEventListener("touchstart",a=>{T=!0;let o=a.touches[0];o&&R(o.clientX)},{passive:!0});let ee=a=>{if(T){let o=a.touches[0];o&&R(o.clientX)}},te=()=>{T=!1};document.addEventListener("touchmove",ee,{passive:!0}),document.addEventListener("touchend",te);let ie=()=>{M&&clearTimeout(M),M=setTimeout(()=>{_&&r.classList.add("hfp-hidden")},3e3)},re=n instanceof ShadowRoot?n.host:n;return re.addEventListener("mousemove",()=>{r.classList.remove("hfp-hidden"),ie()}),re.addEventListener("mouseleave",()=>{_&&r.classList.add("hfp-hidden")}),{updateTime(a,o){let m=o>0?Math.min(a,o):a,pe=o>0?m/o*100:0;l.style.width=`${pe}%`,u.textContent=`${D(m)} / ${D(o)}`},updatePlaying(a){_=a,d.innerHTML=a?ne:U,d.setAttribute("aria-label",a?"Pause":"Play"),a?ie():r.classList.remove("hfp-hidden")},updateSpeed(a){let o=i.indexOf(a);o!==-1&&(k=o),c.textContent=x(a),Q(a)},updateMuted(a){S=a,v.innerHTML=A(a,y),v.setAttribute("aria-label",a?"Unmute":"Mute")},updateVolume(a){y=a,b.style.width=`${a*100}%`,p.setAttribute("aria-valuenow",String(Math.round(a*100))),v.innerHTML=A(S,a)},show(){r.style.display=""},hide(){r.style.display="none"},destroy(){document.removeEventListener("mousemove",Z),document.removeEventListener("mouseup",K),document.removeEventListener("touchmove",ee),document.removeEventListener("touchend",te),document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",B),document.removeEventListener("touchmove",X),document.removeEventListener("touchend",G),document.removeEventListener("click",J),M&&clearTimeout(M)}}}function oe(n){return n.hasRuntime||n.runtimeInjected?!1:!!(n.hasNestedCompositions||n.hasTimelines&&n.attempts>=5)}var j=null;function ge(){if(j)return j;if(typeof CSSStyleSheet>"u")return null;try{let n=new CSSStyleSheet;return n.replaceSync(F),j=n,n}catch{return null}}var W=30,_e="https://cdn.jsdelivr.net/npm/@hyperframes/core/dist/hyperframe.runtime.iife.js",C="shader-capture-scale",w="shader-loading",ye="__hf_shader_capture_scale",Ee="__hf_shader_loading",H=["Preparing scene transitions","Sampling outgoing scene motion","Sampling incoming scene motion","Caching transition frames","Finalizing transition preview"];function de(n){if(n===null)return null;let e=Number(n);return!Number.isFinite(e)||e<=0?null:String(Math.min(1,Math.max(.25,e)))}function le(n){if(n===null||n.trim()==="")return"composition";let e=n.trim().toLowerCase();return e==="none"||e==="false"||e==="0"||e==="off"?"none":e==="player"||e==="true"||e==="1"||e==="on"?"player":"composition"}function he(n,e,t){t===null?n.delete(e):n.set(e,t)}function Se(n,e,t){let i=n.indexOf("#"),r=i>=0?n.slice(0,i):n,d=i>=0?n.slice(i):"",s=r.indexOf("?"),l=s>=0?r.slice(0,s):r,u=s>=0?r.slice(s+1):"",h=new URLSearchParams(u);he(h,ye,e),he(h,Ee,t==="composition"?null:t);let c=h.toString();return`${l}${c?`?${c}`:""}${d}`}function I(n){return typeof n=="object"&&n!==null}function Le(n){return I(n)&&typeof n.getDuration=="function"}function Te(n){return I(n)&&typeof n.duration=="function"&&typeof n.time=="function"&&typeof n.seek=="function"&&typeof n.play=="function"&&typeof n.pause=="function"}function we(n,e,t){if(e===null&&t==="composition")return n;let i=[];e!==null&&i.push(`window.__HF_SHADER_CAPTURE_SCALE=${JSON.stringify(e)};`),t!=="composition"&&i.push(`window.__HF_SHADER_LOADING=${JSON.stringify(t)};`);let r=`<script data-hyperframes-player-shader-options>${i.join("")}</script>`;return/<head\b[^>]*>/i.test(n)?n.replace(/<head\b[^>]*>/i,d=>`${d}${r}`):/<html\b[^>]*>/i.test(n)?n.replace(/<html\b[^>]*>/i,d=>`${d}${r}`):`${r}${n}`}var O=class n extends HTMLElement{static get observedAttributes(){return["src","srcdoc","width","height","controls","muted","volume","poster","playback-rate","audio-src",C,w]}shadow;container;iframe;posterEl=null;controlsApi=null;resizeObserver;shaderLoaderEl;shaderLoaderFillEl;shaderLoaderTitleEl;shaderLoaderDetailEl;shaderLoaderTransitionValueEl;shaderLoaderFrameLabelEl;shaderLoaderFrameValueEl;shaderLoaderFrameRowEl;shaderLoaderHideTimeout=null;_ready=!1;_duration=0;_currentTime=0;_paused=!0;_volume=1;_compositionWidth=1920;_compositionHeight=1080;_probeInterval=null;_lastUpdateMs=0;_directTimelineAdapter=null;_directTimelineRaf=null;_parentTickRaf=null;_parentMedia=[];_audioOwner="runtime";_mediaObserver;_playbackErrorPosted=!1;constructor(){super(),this.shadow=this.attachShadow({mode:"open"});let e=ge();if(e)this.shadow.adoptedStyleSheets=[e];else{let i=document.createElement("style");i.textContent=F,this.shadow.appendChild(i)}this.container=document.createElement("div"),this.container.className="hfp-container",this.iframe=document.createElement("iframe"),this.iframe.className="hfp-iframe",this.iframe.sandbox.add("allow-scripts","allow-same-origin"),this.iframe.allow="autoplay; fullscreen",this.iframe.referrerPolicy="no-referrer",this.iframe.title="HyperFrames Composition",this.container.appendChild(this.iframe),this.shadow.appendChild(this.container);let t=this._createShaderLoader();this.shaderLoaderEl=t.root,this.shaderLoaderFillEl=t.fill,this.shaderLoaderTitleEl=t.title,this.shaderLoaderDetailEl=t.detail,this.shaderLoaderTransitionValueEl=t.transitionValue,this.shaderLoaderFrameLabelEl=t.frameLabel,this.shaderLoaderFrameValueEl=t.frameValue,this.shaderLoaderFrameRowEl=t.frameRow,this.shadow.appendChild(this.shaderLoaderEl),this.addEventListener("click",i=>{this._isControlsClick(i)||(this._paused?this.play():this.pause())}),this.resizeObserver=new ResizeObserver(()=>this._updateScale()),this._onMessage=this._onMessage.bind(this),this._onIframeLoad=this._onIframeLoad.bind(this)}connectedCallback(){this.resizeObserver.observe(this),window.addEventListener("message",this._onMessage),this.iframe.addEventListener("load",this._onIframeLoad),this.hasAttribute("controls")&&this._setupControls(),this.hasAttribute("poster")&&this._setupPoster(),this.hasAttribute("audio-src")&&this._setupParentAudioFromUrl(this.getAttribute("audio-src")),this.hasAttribute("srcdoc")&&(this.iframe.srcdoc=this._prepareSrcdoc(this.getAttribute("srcdoc"))),this.hasAttribute("src")&&(this.iframe.src=this._prepareSrc(this.getAttribute("src")))}disconnectedCallback(){this.resizeObserver.disconnect(),window.removeEventListener("message",this._onMessage),this.iframe.removeEventListener("load",this._onIframeLoad),this._probeInterval&&clearInterval(this._probeInterval),this._stopDirectTimelineClock(),this._stopParentTickClock(),this._directTimelineAdapter=null,this.shaderLoaderHideTimeout&&clearTimeout(this.shaderLoaderHideTimeout),this.shaderLoaderHideTimeout=null,this._teardownMediaObserver(),this.controlsApi?.destroy();for(let e of this._parentMedia)e.el.pause(),e.el.src="";this._parentMedia=[]}attributeChangedCallback(e,t,i){switch(e){case"src":i&&(this._ready=!1,this.iframe.src=this._prepareSrc(i));break;case"srcdoc":this._ready=!1,i!==null?this.iframe.srcdoc=this._prepareSrcdoc(i):this.iframe.removeAttribute("srcdoc");break;case"width":this._compositionWidth=parseInt(i||"1920",10),this._updateScale();break;case"height":this._compositionHeight=parseInt(i||"1080",10),this._updateScale();break;case"controls":i!==null?this._setupControls():(this.controlsApi?.destroy(),this.controlsApi=null);break;case"poster":this._setupPoster();break;case"playback-rate":{let r=parseFloat(i||"1");for(let d of this._parentMedia)d.el.playbackRate=r;this._sendControl("set-playback-rate",{playbackRate:r}),this.controlsApi?.updateSpeed(r),this.dispatchEvent(new Event("ratechange"));break}case"muted":for(let r of this._parentMedia)r.el.muted=i!==null;this._sendControl("set-muted",{muted:i!==null}),this.controlsApi?.updateMuted(i!==null),this.dispatchEvent(new Event("volumechange"));break;case"volume":{let r=Math.max(0,Math.min(1,parseFloat(i||"1")));this._volume=r;for(let d of this._parentMedia)d.el.volume=r;this._sendControl("set-volume",{volume:r}),this.controlsApi?.updateVolume(r),this.dispatchEvent(new Event("volumechange"));break}case"audio-src":i&&this._setupParentAudioFromUrl(i);break;case C:case w:this._reloadShaderOptions();break}}get iframeElement(){return this.iframe}play(){this._hidePoster(),this._duration>0&&this._currentTime>=this._duration&&this.seek(0),this._paused=!1;let e=this._tryDirectTimelinePlay();e||(this._sendControl("play"),this._ready&&!this._directTimelineAdapter&&this._startParentTickClock()),this._audioOwner==="parent"&&this._playParentMedia(),this.controlsApi?.updatePlaying(!0),this.dispatchEvent(new Event("play")),e&&this._startDirectTimelineClock()}pause(){this._tryDirectTimelinePause()||this._sendControl("pause"),this._stopDirectTimelineClock(),this._stopParentTickClock(),this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=!0,this.controlsApi?.updatePlaying(!1),this.dispatchEvent(new Event("pause"))}seek(e){if(!this._trySyncSeek(e)&&!this._tryDirectTimelineSeek(e)){let t=Math.round(e*W);this._sendControl("seek",{frame:t})}if(this._stopDirectTimelineClock(),this._stopParentTickClock(),this._currentTime=e,this._audioOwner==="parent")for(let t of this._parentMedia){let i=e-t.start;i>=0&&i<t.duration&&(t.el.currentTime=i)}this._paused=!0,this.controlsApi?.updatePlaying(!1),this.controlsApi?.updateTime(this._currentTime,this._duration)}get currentTime(){return this._currentTime}set currentTime(e){this.seek(e)}get duration(){return this._duration}get paused(){return this._paused}get ready(){return this._ready}get playbackRate(){return parseFloat(this.getAttribute("playback-rate")||"1")}set playbackRate(e){this.setAttribute("playback-rate",String(e))}get shaderCaptureScale(){return Number(de(this.getAttribute(C))??"1")}set shaderCaptureScale(e){this.setAttribute(C,String(e))}get shaderLoading(){return le(this.getAttribute(w))}set shaderLoading(e){e==="composition"?this.removeAttribute(w):this.setAttribute(w,e)}get muted(){return this.hasAttribute("muted")}set muted(e){e?this.setAttribute("muted",""):this.removeAttribute("muted")}get volume(){return this._volume}set volume(e){this.setAttribute("volume",String(Math.max(0,Math.min(1,e))))}get loop(){return this.hasAttribute("loop")}set loop(e){e?this.setAttribute("loop",""):this.removeAttribute("loop")}_sendControl(e,t={}){try{this.iframe.contentWindow?.postMessage({source:"hf-parent",type:"control",action:e,...t},"*")}catch{}}_shaderCaptureScaleParam(){return de(this.getAttribute(C))}_shaderLoadingMode(){return le(this.getAttribute(w))}_prepareSrc(e){return Se(e,this._shaderCaptureScaleParam(),this._shaderLoadingMode())}_prepareSrcdoc(e){return we(e,this._shaderCaptureScaleParam(),this._shaderLoadingMode())}_reloadShaderOptions(){if(this._shaderLoadingMode()!=="player"&&this._resetShaderLoader(),this.hasAttribute("srcdoc")){this.iframe.srcdoc=this._prepareSrcdoc(this.getAttribute("srcdoc")||"");return}this.hasAttribute("src")&&(this.iframe.src=this._prepareSrc(this.getAttribute("src")||""))}_createShaderLoader(){let e=document.createElement("div");e.className="hfp-shader-loader",e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.setAttribute("aria-label","Preparing scene transitions"),e.setAttribute("data-hyperframes-ignore",""),e.draggable=!1;let t=g=>{g.preventDefault(),g.stopPropagation()};for(let g of["selectstart","dragstart","pointerdown","mousedown","click","dblclick","contextmenu","touchstart"])e.addEventListener(g,t,{capture:!0});let i=document.createElement("div");i.className="hfp-shader-loader-panel",i.draggable=!1;let r=document.createElement("div");r.className="hfp-shader-loader-mark",r.draggable=!1,r.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("");let d=document.createElement("div");d.className="hfp-shader-loader-title";let s=document.createElement("span");s.className="hfp-shader-loader-title-text",s.textContent=H[0]||"Preparing scene transitions",d.appendChild(s);let l=document.createElement("div");l.className="hfp-shader-loader-detail",l.textContent="Rendering animated scene samples for shader transitions.";let u=document.createElement("div");u.className="hfp-shader-loader-track",u.setAttribute("aria-hidden","true");let h=document.createElement("div");h.className="hfp-shader-loader-fill",u.appendChild(h);let c=document.createElement("div");c.className="hfp-shader-loader-progress";let f=g=>{let p=document.createElement("div");p.className="hfp-shader-loader-row";let b=document.createElement("span");b.className="hfp-shader-loader-label",b.textContent=g;let _=document.createElement("span");return _.className="hfp-shader-loader-value",p.appendChild(b),p.appendChild(_),c.appendChild(p),{row:p,label:b,value:_}},E=f("transition"),v=f("transition frame");return i.appendChild(r),i.appendChild(d),i.appendChild(l),i.appendChild(u),i.appendChild(c),e.appendChild(i),{root:e,fill:h,title:s,detail:l,transitionValue:E.value,frameLabel:v.label,frameValue:v.value,frameRow:v.row}}_showShaderLoader(){this.shaderLoaderHideTimeout&&(clearTimeout(this.shaderLoaderHideTimeout),this.shaderLoaderHideTimeout=null),this.shaderLoaderEl.classList.remove("hfp-hiding"),this.shaderLoaderEl.classList.add("hfp-visible")}_hideShaderLoader(){if(this.shaderLoaderEl.classList.contains("hfp-hiding")){this.shaderLoaderHideTimeout||this._scheduleShaderLoaderHideCleanup();return}this.shaderLoaderEl.classList.contains("hfp-visible")&&(this.shaderLoaderEl.classList.add("hfp-hiding"),this.shaderLoaderEl.classList.remove("hfp-visible"),this._scheduleShaderLoaderHideCleanup())}_scheduleShaderLoaderHideCleanup(){this.shaderLoaderHideTimeout&&clearTimeout(this.shaderLoaderHideTimeout),this.shaderLoaderHideTimeout=setTimeout(()=>{this.shaderLoaderEl.classList.remove("hfp-hiding"),this.shaderLoaderHideTimeout=null},420)}_resetShaderLoader(){this.shaderLoaderHideTimeout&&(clearTimeout(this.shaderLoaderHideTimeout),this.shaderLoaderHideTimeout=null),this.shaderLoaderEl.classList.remove("hfp-visible","hfp-hiding"),this.shaderLoaderFillEl.style.transform="scaleX(0)",this.shaderLoaderTransitionValueEl.textContent="",this.shaderLoaderFrameValueEl.textContent="",this.shaderLoaderFrameRowEl.style.visibility="hidden"}_updateShaderLoader(e){if(this._shaderLoadingMode()!=="player"){this._resetShaderLoader();return}if(e.ready||!e.loading){this._hideShaderLoader();return}let t=typeof e.progress=="number"&&Number.isFinite(e.progress)?e.progress:0,i=typeof e.total=="number"&&Number.isFinite(e.total)?e.total:0,r=i>0?Math.min(1,Math.max(0,t/i)):0,d=Math.min(H.length-1,Math.floor(r*H.length));this.shaderLoaderTitleEl.textContent=H[d]||"Preparing scene transitions",this.shaderLoaderDetailEl.textContent=e.phase==="cached"?"Loading cached transition frames before playback.":e.phase==="finalizing"?"Uploading transition textures for smooth playback.":"Rendering animated scene samples for shader transitions.",this.shaderLoaderFillEl.style.transform=`scaleX(${r})`,this.shaderLoaderTransitionValueEl.textContent=e.currentTransition!==void 0&&e.transitionTotal!==void 0?`${e.currentTransition}/${e.transitionTotal}`:i>0?`${t}/${i}`:"";let s=e.transitionFrame!==void 0&&e.transitionFrames!==void 0?`${e.transitionFrame}/${e.transitionFrames}`:"";this.shaderLoaderFrameLabelEl.textContent=e.phase==="cached"?"cached transition frames":e.phase==="finalizing"?"finalizing transition frames":"rendering transition frames",this.shaderLoaderFrameValueEl.textContent=s,this.shaderLoaderFrameRowEl.style.visibility=s?"visible":"hidden",this.shaderLoaderEl.setAttribute("aria-valuenow",String(Math.round(r*100))),this._showShaderLoader()}_trySyncSeek(e){try{let i=this.iframe.contentWindow?.__player,r=i?.seek;return typeof r!="function"?!1:(r.call(i,e),!0)}catch{return!1}}_tryDirectTimelineSeek(e){let t=this._directTimelineAdapter||this._resolveDirectTimelineAdapter();if(!t)return!1;try{return t.seek(e),t.pause(),this._directTimelineAdapter=t,!0}catch{return!1}}_tryDirectTimelinePlay(){let e=this._directTimelineAdapter||this._resolveDirectTimelineAdapter();if(!e)return!1;try{return e.play(),this._directTimelineAdapter=e,!0}catch{return!1}}_tryDirectTimelinePause(){let e=this._directTimelineAdapter||this._resolveDirectTimelineAdapter();if(!e)return!1;try{return e.pause(),this._directTimelineAdapter=e,!0}catch{return!1}}_startDirectTimelineClock(){this._stopDirectTimelineClock();let e=()=>{let t=this._directTimelineAdapter;if(!t||this._paused){this._directTimelineRaf=null;return}let i;try{i=t.time()}catch{this._directTimelineRaf=null;return}this._duration>0&&(i=Math.min(i,this._duration)),this._currentTime=i;let r=this._duration>0&&i>=this._duration,d=performance.now();if((d-this._lastUpdateMs>100||r)&&(this._lastUpdateMs=d,this.controlsApi?.updateTime(this._currentTime,this._duration),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:this._currentTime}}))),r){if(this.loop){this.seek(0),this.play();return}t.pause(),this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=!0,this.controlsApi?.updatePlaying(!1),this.dispatchEvent(new Event("ended")),this._directTimelineRaf=null;return}this._directTimelineRaf=requestAnimationFrame(e)};this._directTimelineRaf=requestAnimationFrame(e)}_stopDirectTimelineClock(){this._directTimelineRaf!==null&&(cancelAnimationFrame(this._directTimelineRaf),this._directTimelineRaf=null)}_startParentTickClock(){this._stopParentTickClock();let 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)}_resolveDirectTimelineAdapter(){try{let e=this.iframe.contentWindow;return e?this._resolveDirectTimelineAdapterFromWindow(e):null}catch{return null}}_resolveDirectTimelineAdapterFromWindow(e){if(this._hasRuntimeBridge(e))return null;let t=Reflect.get(e,"__timelines");if(!I(t))return null;let i=Object.keys(t);if(i.length===0)return null;let r=this.iframe.contentDocument?.querySelector("[data-composition-id]")?.getAttribute("data-composition-id"),d=r&&r in t?r:i[i.length-1],s=t[d];return Te(s)?s:null}_hasRuntimeBridge(e){return Reflect.get(e,"__hf")!==void 0||I(Reflect.get(e,"__player"))}_resolvePlaybackDurationAdapter(e){let t=Reflect.get(e,"__player");if(Le(t))return{kind:"runtime",getDuration:()=>t.getDuration()};let i=this._resolveDirectTimelineAdapterFromWindow(e);return i?{kind:"direct-timeline",timeline:i,getDuration:()=>i.duration()}:null}_isControlsClick(e){return e.composedPath().some(t=>t instanceof HTMLElement&&t.classList.contains("hfp-controls"))}_onMessage(e){if(e.source!==this.iframe.contentWindow)return;let t=e.data;if(!(!t||t.source!=="hf-preview")){if(t.type==="shader-transition-state"){let i=t.state&&typeof t.state=="object"?t.state:{};this._updateShaderLoader(i),this.dispatchEvent(new CustomEvent("shadertransitionstate",{detail:{compositionId:t.compositionId,state:i}}));return}if(t.type==="state"){let i=(t.frame??0)/W;this._currentTime=this._duration>0?Math.min(i,this._duration):i;let r=!this._paused,d=!t.isPlaying,s=this._duration>0&&this._currentTime>=this._duration&&(r||t.isPlaying);if(s&&this.loop){this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=d,this.seek(0),this.play();return}this._paused=d,this._audioOwner==="parent"&&(r&&this._paused?this._pauseParentMedia():!r&&!this._paused&&this._playParentMedia(),this._mirrorParentMediaTime(this._currentTime));let l=performance.now();(l-this._lastUpdateMs>100||this._paused!==r)&&(this._lastUpdateMs=l,this.controlsApi?.updateTime(this._currentTime,this._duration),this.controlsApi?.updatePlaying(!this._paused),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:this._currentTime}}))),s&&(this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=!0,this.controlsApi?.updatePlaying(!1),this.dispatchEvent(new Event("ended")))}t.type==="media-autoplay-blocked"&&this._promoteToParentProxy(),t.type==="timeline"&&t.durationInFrames>0&&Number.isFinite(t.durationInFrames)&&(this._duration=t.durationInFrames/W,this.controlsApi?.updateTime(this._currentTime,this._duration)),t.type==="stage-size"&&t.width>0&&t.height>0&&(this._compositionWidth=t.width,this._compositionHeight=t.height,this._updateScale())}}_runtimeInjected=!1;_onIframeLoad(){let e=0;this._runtimeInjected=!1,this._directTimelineAdapter=null,this._stopDirectTimelineClock(),this._stopParentTickClock(),this._resetShaderLoader();let t=this._audioOwner==="parent";this._audioOwner="runtime",this._playbackErrorPosted=!1,this._pauseParentMedia(),this._teardownMediaObserver(),t&&this.dispatchEvent(new CustomEvent("audioownershipchange",{detail:{owner:"runtime",reason:"iframe-reload"}})),this._probeInterval&&clearInterval(this._probeInterval),this._probeInterval=setInterval(()=>{e++;try{let i=this.iframe.contentWindow;if(!i)return;let r=!!(i.__hf||i.__player),d=!!(i.__timelines&&Object.keys(i.__timelines).length>0),s=!!this.iframe.contentDocument?.querySelector("[data-composition-src]");if(oe({hasRuntime:r,hasTimelines:d,hasNestedCompositions:s,runtimeInjected:this._runtimeInjected,attempts:e})){this._injectRuntime();return}if(this._runtimeInjected&&!r)return;let l=this._resolvePlaybackDurationAdapter(i);if(l&&l.getDuration()>0){clearInterval(this._probeInterval),this._duration=l.getDuration(),this._directTimelineAdapter=l.kind==="direct-timeline"?l.timeline:null,this._ready=!0,this.controlsApi?.updateTime(0,this._duration),this.dispatchEvent(new CustomEvent("ready",{detail:{duration:this._duration}}));let h=this.iframe.contentDocument?.querySelector("[data-composition-id]");if(h){let c=parseInt(h.getAttribute("data-width")||"0",10),f=parseInt(h.getAttribute("data-height")||"0",10);c>0&&f>0&&(this._compositionWidth=c,this._compositionHeight=f,this._updateScale())}this._setupParentMedia(),this.hasAttribute("autoplay")&&this.play();return}}catch{}e>=40&&(clearInterval(this._probeInterval),this.dispatchEvent(new CustomEvent("error",{detail:{message:"Composition timeline not found after 8s"}})))},200)}_injectRuntime(){this._runtimeInjected=!0;try{let e=this.iframe.contentDocument;if(!e)return;let t=e.createElement("script");t.src=_e,t.onload=()=>{},t.onerror=()=>{},(e.head||e.documentElement).appendChild(t)}catch{}}_updateScale(){let e=this.getBoundingClientRect();if(e.width===0||e.height===0)return;let t=Math.min(e.width/this._compositionWidth,e.height/this._compositionHeight);this.iframe.style.width=`${this._compositionWidth}px`,this.iframe.style.height=`${this._compositionHeight}px`,this.iframe.style.transform=`translate(-50%, -50%) scale(${t})`}_setupControls(){if(this.controlsApi)return;let e={onPlay:()=>this.play(),onPause:()=>this.pause(),onSeek:r=>this.seek(r*this._duration),onSpeedChange:r=>{this.playbackRate=r},onMuteToggle:()=>{this.muted=!this.muted},onVolumeChange:r=>{this.volume=r}},t=this.getAttribute("speed-presets"),i=t?t.split(",").map(Number).filter(r=>!isNaN(r)&&r>0):void 0;this.controlsApi=se(this.shadow,e,{speedPresets:i}),this.controlsApi.updateMuted(this.muted),this.controlsApi.updateVolume(this._volume)}_setupPoster(){let e=this.getAttribute("poster");if(!e){this.posterEl?.remove(),this.posterEl=null;return}this.posterEl||(this.posterEl=document.createElement("img"),this.posterEl.className="hfp-poster",this.shadow.appendChild(this.posterEl)),this.posterEl.src=e}_playParentMedia(){for(let e of this._parentMedia)e.el.src&&e.el.play().catch(t=>this._reportPlaybackError(t))}_reportPlaybackError(e){this._playbackErrorPosted||(this._playbackErrorPosted=!0,this.dispatchEvent(new CustomEvent("playbackerror",{detail:{source:"parent-proxy",error:e}})))}_pauseParentMedia(){for(let e of this._parentMedia)e.el.pause()}static MIRROR_DRIFT_THRESHOLD_SECONDS=.05;static MIRROR_REQUIRED_CONSECUTIVE_DRIFT_SAMPLES=2;_mirrorParentMediaTime(e,t){let i=t?.force===!0,r=n.MIRROR_REQUIRED_CONSECUTIVE_DRIFT_SAMPLES,d=n.MIRROR_DRIFT_THRESHOLD_SECONDS;for(let s of this._parentMedia){let l=e-s.start;if(l<0||l>=s.duration){s.driftSamples=0;continue}Math.abs(s.el.currentTime-l)>d?(s.driftSamples+=1,(i||s.driftSamples>=r)&&(s.el.currentTime=l,s.driftSamples=0)):s.driftSamples=0}}_promoteToParentProxy(){if(this._audioOwner!=="parent"){this._audioOwner="parent";try{let e=this.iframe.contentDocument;if(e)for(let t of e.querySelectorAll("video, audio"))t.muted=!0}catch{}this._sendControl("set-media-output-muted",{muted:!0}),this._mirrorParentMediaTime(this._currentTime,{force:!0}),this._paused||this._playParentMedia(),this.dispatchEvent(new CustomEvent("audioownershipchange",{detail:{owner:"parent",reason:"autoplay-blocked"}}))}}_createParentMedia(e,t,i,r){if(this._parentMedia.some(l=>l.el.src===e))return null;let d=t==="video"?document.createElement("video"):new Audio;d.preload="auto",d.src=e,d.load(),d.muted=this.muted,d.volume=this._volume,this.playbackRate!==1&&(d.playbackRate=this.playbackRate);let s={el:d,start:i,duration:r,driftSamples:0};return this._parentMedia.push(s),s}_setupParentAudioFromUrl(e){this._createParentMedia(e,"audio",0,1/0)}_setupParentMedia(){try{let e=this.iframe.contentDocument;if(!e)return;let t=e.querySelectorAll("audio[data-start], video[data-start]");for(let i of t)this._adoptIframeMedia(i);this._observeDynamicMedia(e)}catch{}}_adoptIframeMedia(e){let t=e.getAttribute("src")||e.querySelector("source")?.getAttribute("src");if(!t)return;let i=new URL(t,e.ownerDocument.baseURI).href,r=parseFloat(e.getAttribute("data-start")||"0"),d=parseFloat(e.getAttribute("data-duration")||"Infinity"),s=e.tagName==="VIDEO"?"video":"audio",l=this._createParentMedia(i,s,r,d);l&&this._audioOwner==="parent"&&(this._mirrorParentMediaTime(this._currentTime,{force:!0}),!this._paused&&l.el.src&&l.el.play().catch(u=>this._reportPlaybackError(u)))}_observeDynamicMedia(e){if(this._teardownMediaObserver(),typeof MutationObserver>"u"||!e.body)return;let t=new MutationObserver(r=>{for(let d of r){for(let s of d.addedNodes){if(!(s instanceof Element))continue;let l=[];s.matches?.("audio[data-start], video[data-start]")&&l.push(s);let u=s.querySelectorAll?.("audio[data-start], video[data-start]");if(u)for(let h of u)l.push(h);for(let h of l)this._adoptIframeMedia(h)}for(let s of d.removedNodes){if(!(s instanceof Element))continue;let l=[];s.matches?.("audio[data-start], video[data-start]")&&l.push(s);let u=s.querySelectorAll?.("audio[data-start], video[data-start]");if(u)for(let h of u)l.push(h);for(let h of l)this._detachIframeMedia(h)}}}),i=e.querySelectorAll("[data-composition-id]");if(i.length>0)for(let r of i)t.observe(r,{childList:!0,subtree:!0});else t.observe(e.body,{childList:!0,subtree:!0});this._mediaObserver=t}_teardownMediaObserver(){this._mediaObserver?.disconnect(),this._mediaObserver=void 0}_detachIframeMedia(e){let t=e.getAttribute("src")||e.querySelector("source")?.getAttribute("src");if(!t)return;let i=new URL(t,e.ownerDocument.baseURI).href,r=this._parentMedia.findIndex(s=>s.el.src===i);if(r===-1)return;let d=this._parentMedia[r];d.el.pause(),d.el.src="",this._parentMedia.splice(r,1)}_hidePoster(){this.posterEl?.remove(),this.posterEl=null}};customElements.get("hyperframes-player")||customElements.define("hyperframes-player",O);return be(Me);})();
|
|
419
419
|
//# sourceMappingURL=hyperframes-player.global.js.map
|