hyperframes 0.6.113 → 0.6.114
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/cli.js +969 -605
- package/dist/hyperframe-runtime.js +23 -23
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +23 -23
- package/dist/skills/hyperframes/SKILL.md +1 -0
- package/dist/studio/assets/{hyperframes-player-BRjQ5a5_.js → hyperframes-player-C1qkW56w.js} +1 -1
- package/dist/studio/assets/{index-C0tFko2e.js → index-BR5v5xu2.js} +1 -1
- package/dist/studio/assets/{index-B8Qzwcpc.js → index-DApfviyW.js} +120 -116
- package/dist/studio/assets/index-DS7Kfzvb.css +1 -0
- package/dist/studio/index.html +2 -2
- package/package.json +1 -1
- package/dist/studio/assets/index-DP8pPIk2.css +0 -1
|
@@ -28,6 +28,7 @@ metadata:
|
|
|
28
28
|
| You want to… | Go to |
|
|
29
29
|
| ------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------- |
|
|
30
30
|
| **Make a video** (from a URL, brief, topic, GitHub PR, existing footage, or a single element to animate) | the **video router below** (§ Video routing) |
|
|
31
|
+
| **Author a slideshow / presentation / pitch deck** — discrete slides, fragments, branching, hotspots | `/slideshow` |
|
|
31
32
|
| **Author / edit an HTML composition** — the `data-*` contract, clips, tracks, sub-compositions, variables | `/hyperframes-core` |
|
|
32
33
|
| **Animate** — atomic motion rules, scene blueprints, transitions, runtime adapters (GSAP / Lottie / Three.js / Anime.js / CSS / WAAPI / TypeGPU) | `/hyperframes-animation` |
|
|
33
34
|
| **Creative direction** — `design.md`, palettes, typography, narration, beat planning, audio-reactive | `/hyperframes-creative` |
|
package/dist/studio/assets/{hyperframes-player-BRjQ5a5_.js → hyperframes-player-C1qkW56w.js}
RENAMED
|
@@ -415,4 +415,4 @@ var ue=Object.defineProperty;var ce=(n,t,e)=>t in n?ue(n,t,{enumerable:!0,config
|
|
|
415
415
|
background: var(--hfp-accent, #fff);
|
|
416
416
|
pointer-events: none;
|
|
417
417
|
}
|
|
418
|
-
`,re='<svg width="24" height="24" viewBox="0 0 18 18" fill="currentColor"><polygon points="4,2 16,9 4,16"/></svg>',ye='<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>',ne='<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>',se='<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>',we='<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>',Ae=[.25,.5,1,1.5,2,4];function U(n){return Number.isInteger(n)?`${n}x`:`${n}x`}function oe(n){if(!Number.isFinite(n)||n<0)return"0:00";const t=Math.floor(n),e=Math.floor(t/60),i=t%60;return`${e}:${i.toString().padStart(2,"0")}`}function Ee(n,t,e={}){const i=e.speedPresets??Ae,r=document.createElement("div");r.className="hfp-controls",r.addEventListener("click",o=>{o.stopPropagation()});const s=document.createElement("button");s.className="hfp-play-btn",s.type="button",s.innerHTML=re,s.setAttribute("aria-label","Play");const a=document.createElement("div");a.className="hfp-scrubber";const l=document.createElement("div");l.className="hfp-progress",l.style.width="0%",a.appendChild(l);const p=document.createElement("span");p.className="hfp-time",p.textContent="0:00 / 0:00";const m=document.createElement("div");m.className="hfp-speed-wrap";const u=document.createElement("button");u.className="hfp-speed-btn",u.type="button",u.textContent="1x",u.setAttribute("aria-label","Playback speed");const c=document.createElement("div");c.className="hfp-speed-menu",c.setAttribute("role","menu");for(const o of i){const d=document.createElement("button");d.className="hfp-speed-option",d.type="button",d.setAttribute("role","menuitem"),d.dataset.speed=String(o),d.textContent=U(o),o===1&&d.classList.add("hfp-active"),c.appendChild(d)}m.appendChild(c),m.appendChild(u);const g=document.createElement("div");g.className="hfp-volume-wrap";const f=document.createElement("button");f.className="hfp-mute-btn",f.type="button",f.innerHTML=ne,f.setAttribute("aria-label","Mute");const b=document.createElement("div");b.className="hfp-volume-slider-wrap";const _=document.createElement("div");_.className="hfp-volume-slider",_.setAttribute("role","slider"),_.setAttribute("aria-label","Volume"),_.setAttribute("aria-valuemin","0"),_.setAttribute("aria-valuemax","100"),_.setAttribute("aria-valuenow","100"),_.tabIndex=0;const y=document.createElement("div");y.className="hfp-volume-fill",y.style.width="100%",_.appendChild(y),b.appendChild(_),g.appendChild(b),g.appendChild(f),e.audioLocked&&(g.style.display="none"),r.appendChild(s),r.appendChild(a),r.appendChild(p),r.appendChild(g),r.appendChild(m),n.appendChild(r);let L=!1,A=!1,w=1,k=null;i.indexOf(1);const M=(o,d)=>o?we:d===0||d<.5?se:ne;s.addEventListener("click",o=>{o.stopPropagation(),L?t.onPause():t.onPlay()}),f.addEventListener("click",o=>{o.stopPropagation(),t.onMuteToggle()});let E=!1;const P=o=>{const d=_.getBoundingClientRect(),v=Math.max(0,Math.min(1,(o-d.left)/d.width));w=v,y.style.width=`${v*100}%`,_.setAttribute("aria-valuenow",String(Math.round(v*100))),A&&v>0&&t.onMuteToggle(),f.innerHTML=M(A,v),t.onVolumeChange(v)};_.addEventListener("mousedown",o=>{o.stopPropagation(),E=!0,P(o.clientX)});const j=o=>{E&&P(o.clientX)},B=()=>{E=!1};document.addEventListener("mousemove",j),document.addEventListener("mouseup",B),_.addEventListener("touchstart",o=>{E=!0;const d=o.touches[0];d&&P(d.clientX)},{passive:!0});const W=o=>{if(E){const d=o.touches[0];d&&P(d.clientX)}},q=()=>{E=!1};document.addEventListener("touchmove",W,{passive:!0}),document.addEventListener("touchend",q);const G=.05;_.addEventListener("keydown",o=>{let d=w;if(o.key==="ArrowRight"||o.key==="ArrowUp")d=Math.min(1,w+G);else if(o.key==="ArrowLeft"||o.key==="ArrowDown")d=Math.max(0,w-G);else return;o.preventDefault(),o.stopPropagation(),w=d,y.style.width=`${d*100}%`,_.setAttribute("aria-valuenow",String(Math.round(d*100))),A&&d>0&&t.onMuteToggle(),f.innerHTML=M(A,d),t.onVolumeChange(d)});const X=o=>{for(const d of c.querySelectorAll(".hfp-speed-option"))d.classList.toggle("hfp-active",d.dataset.speed===String(o))};u.addEventListener("click",o=>{o.stopPropagation();const d=c.classList.toggle("hfp-open");u.setAttribute("aria-expanded",String(d))}),c.addEventListener("click",o=>{o.stopPropagation();const d=o.target.closest(".hfp-speed-option");if(!d)return;const v=parseFloat(d.dataset.speed);i.indexOf(v),u.textContent=U(v),X(v),c.classList.remove("hfp-open"),u.setAttribute("aria-expanded","false"),t.onSpeedChange(v)});const Y=()=>{c.classList.remove("hfp-open"),u.setAttribute("aria-expanded","false")};document.addEventListener("click",Y);const R=o=>{const d=a.getBoundingClientRect(),v=Math.max(0,Math.min(1,(o-d.left)/d.width));t.onSeek(v)};let C=!1;a.addEventListener("mousedown",o=>{o.stopPropagation(),C=!0,R(o.clientX)});const Q=o=>{C&&R(o.clientX)},J=()=>{C=!1};document.addEventListener("mousemove",Q),document.addEventListener("mouseup",J),a.addEventListener("touchstart",o=>{C=!0;const d=o.touches[0];d&&R(d.clientX)},{passive:!0});const K=o=>{if(C){const d=o.touches[0];d&&R(d.clientX)}},Z=()=>{C=!1};document.addEventListener("touchmove",K,{passive:!0}),document.addEventListener("touchend",Z);const ee=()=>{k&&clearTimeout(k),k=setTimeout(()=>{L&&r.classList.add("hfp-hidden")},3e3)},I=n instanceof ShadowRoot?n.host:n,te=()=>{r.classList.remove("hfp-hidden"),ee()},ie=()=>{L&&r.classList.add("hfp-hidden")};return I.addEventListener("mousemove",te),I.addEventListener("mouseleave",ie),{updateTime(o,d){const v=d>0?Math.min(o,d):o,he=d>0?v/d*100:0;l.style.width=`${he}%`,p.textContent=`${oe(v)} / ${oe(d)}`},updatePlaying(o){L=o,s.innerHTML=o?ye:re,s.setAttribute("aria-label",o?"Pause":"Play"),o?ee():r.classList.remove("hfp-hidden")},updateSpeed(o){i.indexOf(o),u.textContent=U(o),X(o)},updateMuted(o){A=o,f.innerHTML=M(o,w),f.setAttribute("aria-label",o?"Unmute":"Mute")},updateVolume(o){w=o,y.style.width=`${o*100}%`,_.setAttribute("aria-valuenow",String(Math.round(o*100))),f.innerHTML=M(A,o)},setVolumeControlsHidden(o){g.style.display=o?"none":""},show(){r.style.display=""},hide(){r.style.display="none"},destroy(){document.removeEventListener("mousemove",Q),document.removeEventListener("mouseup",J),document.removeEventListener("touchmove",K),document.removeEventListener("touchend",Z),document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",B),document.removeEventListener("touchmove",W),document.removeEventListener("touchend",q),document.removeEventListener("click",Y),I.removeEventListener("mousemove",te),I.removeEventListener("mouseleave",ie),k&&clearTimeout(k),r.remove()}}}function Ce(n,t,e,i,r,s=!1){const a=i?i.split(",").map(Number).filter(m=>!isNaN(m)&&m>0):void 0,l={...a?{speedPresets:a}:{},audioLocked:s},p=Ee(n,r,l);return p.updateMuted(t),p.updateVolume(e),p}function ae(n,t,e){return t?(e||(e=document.createElement("img"),e.className="hfp-poster",n.appendChild(e)),e.src=t,e):(e==null||e.remove(),null)}function Te(n){return n.composedPath().some(t=>t instanceof HTMLElement&&t.classList.contains("hfp-controls"))}let O=null;function ke(n,t){if(typeof CSSStyleSheet<"u")try{O||(O=new CSSStyleSheet,O.replaceSync(t)),n.adoptedStyleSheets=[O];return}catch{}const e=document.createElement("style");e.textContent=t,n.appendChild(e)}function xe(){const n=document.createElement("div");n.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",n.appendChild(t),{container:n,iframe:t}}function Se(n,t,e,i){const r=n.offsetWidth,s=n.offsetHeight;if(r===0||s===0)return;const a=Math.min(r/e,s/i);t.style.width=`${e}px`,t.style.height=`${i}px`,t.style.transform=`translate(-50%, -50%) scale(${a})`}const Le=100;class Me{constructor(t){h(this,"_raf",null);h(this,"_lastUpdateMs",0);this._callbacks=t}start(t,e,i,r){this.stop();const s=()=>{if(r()){this._raf=null;return}let a;try{a=t.time()}catch{this._raf=null;return}const l=i();l>0&&(a=Math.min(a,l));const p=l>0&&a>=l,m=performance.now();if((m-this._lastUpdateMs>Le||p)&&(this._lastUpdateMs=m,this._callbacks.onTimeUpdate(a,l)),p){if(this._callbacks.getLoop()){this._callbacks.restart();return}try{t.pause()}catch{}this._callbacks.onPaused(),this._raf=null;return}this._raf=requestAnimationFrame(s)};this._raf=requestAnimationFrame(s)}stop(){this._raf!==null&&(cancelAnimationFrame(this._raf),this._raf=null)}get isRunning(){return this._raf!==null}}function Pe(n){const t=Array.from(n.querySelectorAll("[data-composition-id]"));if(t.length===0)return n.body?[n.body]:[];const e=[];for(const i of t)Ie(i)||e.push(i);return Re(n),e}function Re(n){const t=n.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 r of e)r.closest("[data-composition-id]")||i.push(r);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 Ie(n){let t=n.parentElement;for(;t;){if(t.hasAttribute("data-composition-id"))return!0;t=t.parentElement}return!1}const Oe=.05,Ne=2;class De{constructor(t){h(this,"_entries",[]);h(this,"_mediaObserver");h(this,"_playbackErrorPosted",!1);h(this,"_audioOwner","runtime");h(this,"_urlAudioEntry",null);h(this,"_urlAudioSrc",null);h(this,"_dispatchEvent");h(this,"_getMuted");h(this,"_getVolume");h(this,"_getPlaybackRate");h(this,"_getCurrentTime");h(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(),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}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);const e=this._getCurrentTime()-t.start;e<0||e>=t.duration||this._playEntry(t)}_refreshEntryBounds(t){var r;if(!((r=t.source)!=null&&r.isConnected))return;const e=parseFloat(t.source.getAttribute("data-start")||"0");t.start=Number.isFinite(e)?e:0;const i=parseFloat(t.source.getAttribute("data-duration")||"");t.duration=Number.isFinite(i)&&i>0?i:Number.POSITIVE_INFINITY}_gateEntryPlayback(t,e){return e<0||e>=t.duration?(t.el.paused||t.el.pause(),t.driftSamples=0,!1):(this._audioOwner==="parent"&&!this._isPaused()&&t.el.paused&&this._playEntry(t),!0)}playAll(){for(const t of this._entries)this._playEntryIfActive(t)}pauseAll(){for(const t of this._entries)t.el.pause()}seekAll(t){for(const e of this._entries){this._refreshEntryBounds(e);const i=t-e.start;i>=0&&i<e.duration&&(e.el.currentTime=i)}}mirrorTime(t,e){const i=(e==null?void 0:e.force)===!0;for(const r of this._entries){this._refreshEntryBounds(r);const s=t-r.start;this._gateEntryPlayback(r,s)&&(Math.abs(r.el.currentTime-s)>Oe?(r.driftSamples+=1,(i||r.driftSamples>=Ne)&&(r.el.currentTime=s,r.driftSamples=0)):r.driftSamples=0)}}promoteToParentProxy(t,e){if(this._audioOwner==="parent")return;if(this._audioOwner="parent",t)for(const r of t.querySelectorAll("video, audio"))r.muted=!0;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)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=e?t:null,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,r,s){if(this._entries.some(m=>m.el.src===t))return null;const a=e==="video"?document.createElement("video"):new Audio;a.preload="auto",a.src=t,a.load(),a.muted=this._getMuted(),a.volume=this._getVolume();const l=this._getPlaybackRate();l!==1&&(a.playbackRate=l);const p={el:a,start:i,duration:r,driftSamples:0,source:s};return 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")return;const e=this._resolveIframeMediaSrc(t);if(!e)return;const i=parseFloat(t.getAttribute("data-start")||"0"),r=parseFloat(t.getAttribute("data-duration")||"Infinity"),s=t.tagName==="VIDEO"?"video":"audio",a=this._createEntry(e,s,i,r,t);a&&this._audioOwner==="parent"&&(this.mirrorTime(this._getCurrentTime(),{force:!0}),this._isPaused()||this._playEntryIfActive(a))}_detachIframeMedia(t){const e=this._resolveIframeMediaSrc(t);if(!e)return;const i=this._entries.findIndex(s=>s.el.src===e);if(i===-1)return;const r=this._entries[i];r.el.pause(),r.el.src="",this._entries.splice(i,1)}_observeDynamicMedia(t){if(this.teardownObserver(),typeof MutationObserver>"u"||!t.body)return;const e=new MutationObserver(s=>{var a,l,p,m;for(const u of s){if(u.type==="attributes"&&u.attributeName==="preload"){const c=u.target;c instanceof HTMLMediaElement&&c.matches("audio[data-start], video[data-start]")&&c.preload==="auto"&&this._adoptIframeMedia(c);continue}for(const c of u.addedNodes){if(!(c instanceof Element))continue;const g=[];(a=c.matches)!=null&&a.call(c,"audio[data-start], video[data-start]")&&g.push(c);const f=(l=c.querySelectorAll)==null?void 0:l.call(c,"audio[data-start], video[data-start]");if(f)for(const b of f)g.push(b);for(const b of g)this._adoptIframeMedia(b)}for(const c of u.removedNodes){if(!(c instanceof Element))continue;const g=[];(p=c.matches)!=null&&p.call(c,"audio[data-start], video[data-start]")&&g.push(c);const f=(m=c.querySelectorAll)==null?void 0:m.call(c,"audio[data-start], video[data-start]");if(f)for(const b of f)g.push(b);for(const b of g)this._detachIframeMedia(b)}}}),i={childList:!0,subtree:!0,attributes:!0,attributeFilter:["preload"]},r=Pe(t);for(const s of r)e.observe(s,i);this._mediaObserver=e}}const Fe=100;function Ue(n,t,e,i){const r=(n.frame??0)/t,s=e.duration>0?Math.min(r,e.duration):r,a=!e.paused,l=!n.isPlaying,p=e.duration>0&&s>=e.duration&&(a||n.isPlaying);if(p&&i.getLoop())return i.media.audioOwner==="parent"&&i.media.pauseAll(),i.seek(0),i.play(),{...e,currentTime:s,paused:!1};const m={...e,currentTime:s,paused:l};i.media.audioOwner==="parent"&&(a&&l?i.media.pauseAll():!a&&!l&&i.media.playAll(),i.media.mirrorTime(s));const u=performance.now(),c=l!==e.paused;return(u-e.lastUpdateMs>Fe||c)&&(m.lastUpdateMs=u,i.updateControlsTime(s,e.duration),i.updateControlsPlaying(!l),i.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:s}}))),p&&(i.media.audioOwner==="parent"&&i.media.pauseAll(),m.paused=!0,i.updateControlsPlaying(!1),i.dispatchEvent(new Event("ended"))),m}const de=30;function He(n,t,e){if(n.source!==t)return;const i=n.data;if(!(!i||i.source!=="hf-preview")){if(i.type==="shader-transition-state"){const r=i.state&&typeof i.state=="object"?i.state:{};e.shaderLoader.update(r,e.getShaderLoadingMode()),e.dispatchEvent(new CustomEvent("shadertransitionstate",{detail:{compositionId:i.compositionId,state:r}}));return}if(i.type==="ready"){e.onRuntimeReady();return}if(i.type==="state"){e.setPlaybackState(Ue({frame:i.frame??0,isPlaying:!!i.isPlaying},de,e.getPlaybackState(),e));return}if(i.type==="media-autoplay-blocked"){let r=null;try{r=e.getIframeDoc()}catch{}e.media.promoteToParentProxy(r,(s,a)=>e.media.mirrorTime(s,a)),e.sendControl("set-media-output-muted",{muted:!0});return}if(i.type==="timeline"&&i.durationInFrames>0){if(Number.isFinite(i.durationInFrames)){const r=e.getPlaybackState(),s=i.durationInFrames/de;e.setPlaybackState({...r,duration:s}),e.updateControlsTime(r.currentTime,s)}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)}}const T="shader-capture-scale",x="shader-loading",Ve="__hf_shader_capture_scale",$e="__hf_shader_loading",N=["Preparing scene transitions","Sampling outgoing scene motion","Sampling incoming scene motion","Caching transition frames","Finalizing transition preview"];function z(n){if(n===null)return null;const t=Number(n);return!Number.isFinite(t)||t<=0?null:String(Math.min(1,Math.max(.25,t)))}function ze(n){if(n===null||n.trim()==="")return"composition";const t=n.trim().toLowerCase();return t==="none"||t==="false"||t==="0"||t==="off"?"none":t==="player"||t==="true"||t==="1"||t==="on"?"player":"composition"}function le(n,t,e){e===null?n.delete(t):n.set(t,e)}function je(n,t,e){const i=n.indexOf("#"),r=i>=0?n.slice(0,i):n,s=i>=0?n.slice(i):"",a=r.indexOf("?"),l=a>=0?r.slice(0,a):r,p=a>=0?r.slice(a+1):"",m=new URLSearchParams(p);le(m,Ve,t),le(m,$e,e==="composition"?null:e);const u=m.toString();return`${l}${u?`?${u}`:""}${s}`}function Be(n,t,e){if(t===null&&e==="composition")return n;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 r=`<script data-hyperframes-player-shader-options>${i.join("")}<\/script>`;return/<head\b[^>]*>/i.test(n)?n.replace(/<head\b[^>]*>/i,s=>`${s}${r}`):/<html\b[^>]*>/i.test(n)?n.replace(/<html\b[^>]*>/i,s=>`${s}${r}`):`${r}${n}`}function S(n){return ze(n.getAttribute(x))}function We(n){return Number(z(n.getAttribute(T))??"1")}function H(n,t){return je(t,z(n.getAttribute(T)),S(n))}function V(n,t){return Be(t,z(n.getAttribute(T)),S(n))}function qe(){const n=document.createElement("div");n.className="hfp-shader-loader",n.setAttribute("role","status"),n.setAttribute("aria-live","polite"),n.setAttribute("aria-label","Preparing scene transitions"),n.setAttribute("data-hyperframes-ignore",""),n.draggable=!1;const t=f=>{f.preventDefault(),f.stopPropagation()};for(const f of["selectstart","dragstart","pointerdown","mousedown","click","dblclick","contextmenu","touchstart"])n.addEventListener(f,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 r=document.createElement("div");r.className="hfp-shader-loader-title";const s=document.createElement("span");s.className="hfp-shader-loader-title-text",s.textContent=N[0],r.appendChild(s);const a=document.createElement("div");a.className="hfp-shader-loader-detail",a.textContent="Rendering animated scene samples for shader transitions.";const l=document.createElement("div");l.className="hfp-shader-loader-track",l.setAttribute("aria-hidden","true");const p=document.createElement("div");p.className="hfp-shader-loader-fill",l.appendChild(p);const m=document.createElement("div");m.className="hfp-shader-loader-progress";const u=f=>{const b=document.createElement("div");b.className="hfp-shader-loader-row";const _=document.createElement("span");_.className="hfp-shader-loader-label",_.textContent=f;const y=document.createElement("span");return y.className="hfp-shader-loader-value",b.appendChild(_),b.appendChild(y),m.appendChild(b),{row:b,label:_,value:y}},c=u("transition"),g=u("transition frame");return e.appendChild(i),e.appendChild(r),e.appendChild(a),e.appendChild(l),e.appendChild(m),n.appendChild(e),{root:n,fill:p,title:s,detail:a,transitionValue:c.value,frameLabel:g.label,frameValue:g.value,frameRow:g.row}}const Ge=420;class Xe{constructor(t){h(this,"_el");h(this,"_hideTimeout",null);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())}reset(){this._hideTimeout&&(clearTimeout(this._hideTimeout),this._hideTimeout=null),this._el.root.classList.remove("hfp-visible","hfp-hiding"),this._el.fill.style.transform="scaleX(0)",this._el.transitionValue.textContent="",this._el.frameValue.textContent="",this._el.frameRow.style.visibility="hidden"}update(t,e){if(e!=="player"){this.reset();return}if(t.ready||!t.loading){this.hide();return}const i=typeof t.progress=="number"&&Number.isFinite(t.progress)?t.progress:0,r=typeof t.total=="number"&&Number.isFinite(t.total)?t.total:0,s=r>0?Math.min(1,Math.max(0,i/r)):0,a=Math.min(N.length-1,Math.floor(s*N.length));this._el.title.textContent=N[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(${s})`,this._el.transitionValue.textContent=t.currentTransition!==void 0&&t.transitionTotal!==void 0?`${t.currentTransition}/${t.transitionTotal}`:r>0?`${i}/${r}`:"";const l=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.frameValue.textContent=l,this._el.frameRow.style.visibility=l?"visible":"hidden",this._el.root.setAttribute("aria-valuenow",String(Math.round(s*100))),this.show()}get hideTimeout(){return this._hideTimeout}destroy(){this._hideTimeout&&(clearTimeout(this._hideTimeout),this._hideTimeout=null)}_scheduleCleanup(){this._hideTimeout&&clearTimeout(this._hideTimeout),this._hideTimeout=setTimeout(()=>{this._el.root.classList.remove("hfp-hiding"),this._hideTimeout=null},Ge)}}const Ye=.1,Qe=5;function $(n){return!Number.isFinite(n)||n<=0?1:Math.max(Ye,Math.min(Qe,n))}class Je extends HTMLElement{constructor(){super();h(this,"shadow");h(this,"container");h(this,"iframe");h(this,"posterEl",null);h(this,"controlsApi",null);h(this,"resizeObserver");h(this,"shaderLoader");h(this,"probe");h(this,"_ready",!1);h(this,"_currentTime",0);h(this,"_duration",0);h(this,"_paused",!0);h(this,"_lastUpdateMs",0);h(this,"_volume",1);h(this,"_compositionWidth",1920);h(this,"_compositionHeight",1080);h(this,"_directTimelineAdapter",null);h(this,"_directTimelineClock");h(this,"_parentTickRaf",null);h(this,"_media");this.shadow=this.attachShadow({mode:"open"}),ke(this.shadow,ve),{container:this.container,iframe:this.iframe}=xe(),this.shadow.appendChild(this.container);const e=qe();this.shadow.appendChild(e.root),this.shaderLoader=new Xe(e),this._media=new De({dispatchEvent:i=>this.dispatchEvent(i),getMuted:()=>this.muted,getVolume:()=>this._volume,getPlaybackRate:()=>this.playbackRate,getCurrentTime:()=>this._currentTime,isPaused:()=>this._paused}),this._directTimelineClock=new Me({onTimeUpdate:(i,r)=>{var s;this._currentTime=i,(s=this.controlsApi)==null||s.updateTime(i,r),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:i}}))},getLoop:()=>this.loop,restart:()=>{this.seek(0),this.play()},onPaused:()=>{var i;this._media.audioOwner==="parent"&&this._media.pauseAll(),this._paused=!0,(i=this.controlsApi)==null||i.updatePlaying(!1),this.dispatchEvent(new Event("ended"))},onEnded:()=>this.loop}),this.probe=new be(this.iframe,{onReady:i=>this._onProbeReady(i),onError:i=>this.dispatchEvent(new CustomEvent("error",{detail:{message:i}}))}),this.addEventListener("click",i=>{Te(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)}static get observedAttributes(){return["src","srcdoc","width","height","controls","muted","audio-locked","volume","poster","playback-rate","audio-src",T,x]}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.posterEl=ae(this.shadow,this.getAttribute("poster"),this.posterEl)),this.hasAttribute("audio-src")&&this._media.setupFromUrl(this.getAttribute("audio-src")),this.hasAttribute("srcdoc")&&(this.iframe.srcdoc=V(this,this.getAttribute("srcdoc"))),this.hasAttribute("src")&&(this.iframe.src=H(this,this.getAttribute("src"))),!this.hasAttribute("audio-locked")&&this._isLockedHostEnvironment()&&this._applyAudioLock(!0)}disconnectedCallback(){var e;this.resizeObserver.disconnect(),window.removeEventListener("message",this._onMessage),this.iframe.removeEventListener("load",this._onIframeLoad),this.probe.stop(),this._directTimelineClock.stop(),this._stopParentTickClock(),this._directTimelineAdapter=null,this.shaderLoader.destroy(),this._media.destroy(),(e=this.controlsApi)==null||e.destroy()}attributeChangedCallback(e,i,r){var s,a,l,p,m;switch(e){case"src":r&&(this._ready=!1,this.iframe.src=H(this,r));break;case"srcdoc":this._ready=!1,r!==null?this.iframe.srcdoc=V(this,r):this.iframe.removeAttribute("srcdoc");break;case"width":this._compositionWidth=F(r)??1920,this._rescale();break;case"height":this._compositionHeight=F(r)??1080,this._rescale();break;case"controls":r!==null?this._setupControls():((s=this.controlsApi)==null||s.destroy(),this.controlsApi=null);break;case"poster":this.posterEl=ae(this.shadow,r,this.posterEl);break;case"playback-rate":{const u=$(parseFloat(r||"1"));this._media.updatePlaybackRate(u),this._sendControl("set-playback-rate",{playbackRate:u}),(l=(a=this._directTimelineAdapter)==null?void 0:a.timeScale)==null||l.call(a,u),(p=this.controlsApi)==null||p.updateSpeed(u),this.dispatchEvent(new Event("ratechange"));break}case"muted":this._handleMutedChange(r);break;case"audio-locked":this._applyAudioLock(r!==null);break;case"volume":{const u=Math.max(0,Math.min(1,parseFloat(r||"1")));this._volume=u,this._media.updateVolume(u),this._sendControl("set-volume",{volume:u}),(m=this.controlsApi)==null||m.updateVolume(u),this.dispatchEvent(new Event("volumechange"));break}case"audio-src":r?this._media.setupFromUrl(r):this._media.teardownUrlAudio();break;case T:case x:this._reloadShaderOptions();break}}get iframeElement(){return this.iframe}play(){var i,r;(i=this.posterEl)==null||i.remove(),this.posterEl=null,this._duration>0&&this._currentTime>=this._duration&&this.seek(0),this._paused=!1;const e=this._tryDirectTimelinePlay();e||(this._sendControl("play"),this._ready&&!this._directTimelineAdapter&&this._startParentTickClock()),this._media.audioOwner==="parent"&&this._media.playAll(),(r=this.controlsApi)==null||r.updatePlaying(!0),this.dispatchEvent(new Event("play")),e&&this._directTimelineAdapter&&this._directTimelineClock.start(this._directTimelineAdapter,()=>this._currentTime,()=>this._duration,()=>this._paused)}pause(){var e;this._tryDirectTimelinePause()||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.dispatchEvent(new Event("pause"))}seek(e){var i,r;!this._trySyncSeek(e)&&!this._tryDirectTimelineSeek(e)&&this._sendControl("seek",{frame:Math.round(e*30)}),this._directTimelineClock.stop(),this._stopParentTickClock(),this._currentTime=e,this._media.audioOwner==="parent"&&(this._media.pauseAll(),this._media.seekAll(e)),this._paused=!0,(i=this.controlsApi)==null||i.updatePlaying(!1),(r=this.controlsApi)==null||r.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}})}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 We(this)}set shaderCaptureScale(e){this.setAttribute(T,String(e))}get shaderLoading(){return S(this)}set shaderLoading(e){e==="composition"?this.removeAttribute(x):this.setAttribute(x,e)}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()}_handleMutedChange(e){var i;if(e===null&&this._isAudioLocked()){this.setAttribute("muted","");return}this._media.updateMuted(e!==null),this._sendControl("set-muted",{muted:e!==null}),(i=this.controlsApi)==null||i.updateMuted(e!==null),this.dispatchEvent(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 loop(){return this.hasAttribute("loop")}set loop(e){e?this.setAttribute("loop",""):this.removeAttribute("loop")}_sendControl(e,i={}){var r;try{(r=this.iframe.contentWindow)==null||r.postMessage({source:"hf-parent",type:"control",action:e,...i},"*")}catch{}}_replayBridgeState(){this._sendControl("set-muted",{muted:this.muted}),this._sendControl("set-volume",{volume:this._volume}),this._sendControl("set-playback-rate",{playbackRate:this.playbackRate})}_reloadShaderOptions(){if(S(this)!=="player"&&this.shaderLoader.reset(),this.hasAttribute("srcdoc")){this.iframe.srcdoc=V(this,this.getAttribute("srcdoc")||"");return}this.hasAttribute("src")&&(this.iframe.src=H(this,this.getAttribute("src")||""))}_trySyncSeek(e){try{const i=this.iframe.contentWindow,r=i==null?void 0:i.__player;return typeof(r==null?void 0:r.seek)!="function"?!1:(r.seek.call(r,e),!0)}catch{return!1}}_withDirectTimeline(e){const i=this._directTimelineAdapter||this.probe.resolveDirectTimelineAdapter();if(!i)return!1;try{return e(i),this._directTimelineAdapter=i,!0}catch{return!1}}_tryDirectTimelineSeek(e){return this._withDirectTimeline(i=>{i.seek(e),i.pause()})}_tryDirectTimelinePlay(){return this._withDirectTimeline(e=>void e.play())}_tryDirectTimelinePause(){return this._withDirectTimeline(e=>void e.pause())}_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){He(e,this.iframe.contentWindow,{getPlaybackState:()=>({currentTime:this._currentTime,duration:this._duration,paused:this._paused,lastUpdateMs:this._lastUpdateMs}),setPlaybackState:({currentTime:i,duration:r,paused:s,lastUpdateMs:a})=>{this._currentTime=i,this._duration=r,this._paused=s,this._lastUpdateMs=a},getShaderLoadingMode:()=>S(this),shaderLoader:this.shaderLoader,setCompositionSize:(i,r)=>{this._compositionWidth=i,this._compositionHeight=r,this._rescale()},sendControl:(i,r)=>this._sendControl(i,r),getIframeDoc:()=>this.iframe.contentDocument,onRuntimeReady:()=>this._replayBridgeState(),updateControlsTime:(i,r)=>{var s;return(s=this.controlsApi)==null?void 0:s.updateTime(i,r)},updateControlsPlaying:i=>{var r;return(r=this.controlsApi)==null?void 0:r.updatePlaying(i)},dispatchEvent:i=>this.dispatchEvent(i),seek:i=>this.seek(i),play:()=>this.play(),getLoop:()=>this.loop,media:this._media})}_onProbeReady({duration:e,adapter:i,compositionSize:r}){var s;this._duration=e,this._directTimelineAdapter=i.kind==="direct-timeline"?i.timeline:null,this._ready=!0,(s=this.controlsApi)==null||s.updateTime(0,e),this.dispatchEvent(new CustomEvent("ready",{detail:{duration:e}})),r&&(this._compositionWidth=r.width,this._compositionHeight=r.height,this._rescale());try{const a=this.iframe.contentDocument;a&&this._media.setupFromIframe(a)}catch{}this.hasAttribute("autoplay")&&this.play()}_rescale(){Se(this,this.iframe,this._compositionWidth,this._compositionHeight)}_onIframeLoad(){this._directTimelineAdapter=null,this._directTimelineClock.stop(),this._stopParentTickClock(),this.shaderLoader.reset(),this._media.resetForIframeLoad(),this.probe.start()}_setupControls(){this.controlsApi||(this.controlsApi=Ce(this.shadow,this.muted,this._volume,this.getAttribute("speed-presets"),{onPlay:()=>this.play(),onPause:()=>this.pause(),onSeek:e=>this.seek(e*this._duration),onSpeedChange:e=>void(this.playbackRate=e),onMuteToggle:()=>void(this.muted=!this.muted),onVolumeChange:e=>void(this.volume=e)},this._isAudioLocked()))}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,r)=>this._mirrorParentMediaTime(i,r)),this._sendControl("set-media-output-muted",{muted:!0})}_observeDynamicMedia(e){this._media.setupFromIframe(e)}}customElements.get("hyperframes-player")||customElements.define("hyperframes-player",Je);export{Je as HyperframesPlayer,Ae as SPEED_PRESETS,U as formatSpeed,oe as formatTime};
|
|
418
|
+
`,re='<svg width="24" height="24" viewBox="0 0 18 18" fill="currentColor"><polygon points="4,2 16,9 4,16"/></svg>',ye='<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>',ne='<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>',se='<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>',we='<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>',Ae=[.25,.5,1,1.5,2,4];function U(n){return Number.isInteger(n)?`${n}x`:`${n}x`}function oe(n){if(!Number.isFinite(n)||n<0)return"0:00";const t=Math.floor(n),e=Math.floor(t/60),i=t%60;return`${e}:${i.toString().padStart(2,"0")}`}function Ee(n,t,e={}){const i=e.speedPresets??Ae,r=document.createElement("div");r.className="hfp-controls",r.addEventListener("click",o=>{o.stopPropagation()});const s=document.createElement("button");s.className="hfp-play-btn",s.type="button",s.innerHTML=re,s.setAttribute("aria-label","Play");const a=document.createElement("div");a.className="hfp-scrubber";const l=document.createElement("div");l.className="hfp-progress",l.style.width="0%",a.appendChild(l);const p=document.createElement("span");p.className="hfp-time",p.textContent="0:00 / 0:00";const m=document.createElement("div");m.className="hfp-speed-wrap";const u=document.createElement("button");u.className="hfp-speed-btn",u.type="button",u.textContent="1x",u.setAttribute("aria-label","Playback speed");const c=document.createElement("div");c.className="hfp-speed-menu",c.setAttribute("role","menu");for(const o of i){const d=document.createElement("button");d.className="hfp-speed-option",d.type="button",d.setAttribute("role","menuitem"),d.dataset.speed=String(o),d.textContent=U(o),o===1&&d.classList.add("hfp-active"),c.appendChild(d)}m.appendChild(c),m.appendChild(u);const g=document.createElement("div");g.className="hfp-volume-wrap";const f=document.createElement("button");f.className="hfp-mute-btn",f.type="button",f.innerHTML=ne,f.setAttribute("aria-label","Mute");const b=document.createElement("div");b.className="hfp-volume-slider-wrap";const _=document.createElement("div");_.className="hfp-volume-slider",_.setAttribute("role","slider"),_.setAttribute("aria-label","Volume"),_.setAttribute("aria-valuemin","0"),_.setAttribute("aria-valuemax","100"),_.setAttribute("aria-valuenow","100"),_.tabIndex=0;const y=document.createElement("div");y.className="hfp-volume-fill",y.style.width="100%",_.appendChild(y),b.appendChild(_),g.appendChild(b),g.appendChild(f),e.audioLocked&&(g.style.display="none"),r.appendChild(s),r.appendChild(a),r.appendChild(p),r.appendChild(g),r.appendChild(m),n.appendChild(r);let L=!1,A=!1,w=1,k=null;i.indexOf(1);const M=(o,d)=>o?we:d===0||d<.5?se:ne;s.addEventListener("click",o=>{o.stopPropagation(),L?t.onPause():t.onPlay()}),f.addEventListener("click",o=>{o.stopPropagation(),t.onMuteToggle()});let E=!1;const P=o=>{const d=_.getBoundingClientRect(),v=Math.max(0,Math.min(1,(o-d.left)/d.width));w=v,y.style.width=`${v*100}%`,_.setAttribute("aria-valuenow",String(Math.round(v*100))),A&&v>0&&t.onMuteToggle(),f.innerHTML=M(A,v),t.onVolumeChange(v)};_.addEventListener("mousedown",o=>{o.stopPropagation(),E=!0,P(o.clientX)});const j=o=>{E&&P(o.clientX)},B=()=>{E=!1};document.addEventListener("mousemove",j),document.addEventListener("mouseup",B),_.addEventListener("touchstart",o=>{E=!0;const d=o.touches[0];d&&P(d.clientX)},{passive:!0});const W=o=>{if(E){const d=o.touches[0];d&&P(d.clientX)}},q=()=>{E=!1};document.addEventListener("touchmove",W,{passive:!0}),document.addEventListener("touchend",q);const G=.05;_.addEventListener("keydown",o=>{let d=w;if(o.key==="ArrowRight"||o.key==="ArrowUp")d=Math.min(1,w+G);else if(o.key==="ArrowLeft"||o.key==="ArrowDown")d=Math.max(0,w-G);else return;o.preventDefault(),o.stopPropagation(),w=d,y.style.width=`${d*100}%`,_.setAttribute("aria-valuenow",String(Math.round(d*100))),A&&d>0&&t.onMuteToggle(),f.innerHTML=M(A,d),t.onVolumeChange(d)});const X=o=>{for(const d of c.querySelectorAll(".hfp-speed-option"))d.classList.toggle("hfp-active",d.dataset.speed===String(o))};u.addEventListener("click",o=>{o.stopPropagation();const d=c.classList.toggle("hfp-open");u.setAttribute("aria-expanded",String(d))}),c.addEventListener("click",o=>{o.stopPropagation();const d=o.target.closest(".hfp-speed-option");if(!d)return;const v=parseFloat(d.dataset.speed);i.indexOf(v),u.textContent=U(v),X(v),c.classList.remove("hfp-open"),u.setAttribute("aria-expanded","false"),t.onSpeedChange(v)});const Y=()=>{c.classList.remove("hfp-open"),u.setAttribute("aria-expanded","false")};document.addEventListener("click",Y);const R=o=>{const d=a.getBoundingClientRect(),v=Math.max(0,Math.min(1,(o-d.left)/d.width));t.onSeek(v)};let C=!1;a.addEventListener("mousedown",o=>{o.stopPropagation(),C=!0,R(o.clientX)});const Q=o=>{C&&R(o.clientX)},J=()=>{C=!1};document.addEventListener("mousemove",Q),document.addEventListener("mouseup",J),a.addEventListener("touchstart",o=>{C=!0;const d=o.touches[0];d&&R(d.clientX)},{passive:!0});const K=o=>{if(C){const d=o.touches[0];d&&R(d.clientX)}},Z=()=>{C=!1};document.addEventListener("touchmove",K,{passive:!0}),document.addEventListener("touchend",Z);const ee=()=>{k&&clearTimeout(k),k=setTimeout(()=>{L&&r.classList.add("hfp-hidden")},3e3)},I=n instanceof ShadowRoot?n.host:n,te=()=>{r.classList.remove("hfp-hidden"),ee()},ie=()=>{L&&r.classList.add("hfp-hidden")};return I.addEventListener("mousemove",te),I.addEventListener("mouseleave",ie),{updateTime(o,d){const v=d>0?Math.min(o,d):o,he=d>0?v/d*100:0;l.style.width=`${he}%`,p.textContent=`${oe(v)} / ${oe(d)}`},updatePlaying(o){L=o,s.innerHTML=o?ye:re,s.setAttribute("aria-label",o?"Pause":"Play"),o?ee():r.classList.remove("hfp-hidden")},updateSpeed(o){i.indexOf(o),u.textContent=U(o),X(o)},updateMuted(o){A=o,f.innerHTML=M(o,w),f.setAttribute("aria-label",o?"Unmute":"Mute")},updateVolume(o){w=o,y.style.width=`${o*100}%`,_.setAttribute("aria-valuenow",String(Math.round(o*100))),f.innerHTML=M(A,o)},setVolumeControlsHidden(o){g.style.display=o?"none":""},show(){r.style.display=""},hide(){r.style.display="none"},destroy(){document.removeEventListener("mousemove",Q),document.removeEventListener("mouseup",J),document.removeEventListener("touchmove",K),document.removeEventListener("touchend",Z),document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",B),document.removeEventListener("touchmove",W),document.removeEventListener("touchend",q),document.removeEventListener("click",Y),I.removeEventListener("mousemove",te),I.removeEventListener("mouseleave",ie),k&&clearTimeout(k),r.remove()}}}function Ce(n,t,e,i,r,s=!1){const a=i?i.split(",").map(Number).filter(m=>!isNaN(m)&&m>0):void 0,l={...a?{speedPresets:a}:{},audioLocked:s},p=Ee(n,r,l);return p.updateMuted(t),p.updateVolume(e),p}function ae(n,t,e){return t?(e||(e=document.createElement("img"),e.className="hfp-poster",n.appendChild(e)),e.src=t,e):(e==null||e.remove(),null)}function Te(n){return n.composedPath().some(t=>t instanceof HTMLElement&&t.classList.contains("hfp-controls"))}let O=null;function ke(n,t){if(typeof CSSStyleSheet<"u")try{O||(O=new CSSStyleSheet,O.replaceSync(t)),n.adoptedStyleSheets=[O];return}catch{}const e=document.createElement("style");e.textContent=t,n.appendChild(e)}function xe(){const n=document.createElement("div");n.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",n.appendChild(t),{container:n,iframe:t}}function Se(n,t,e,i){const r=n.offsetWidth,s=n.offsetHeight;if(r===0||s===0)return;const a=Math.min(r/e,s/i);t.style.width=`${e}px`,t.style.height=`${i}px`,t.style.transform=`translate(-50%, -50%) scale(${a})`}const Le=100;class Me{constructor(t){h(this,"_raf",null);h(this,"_lastUpdateMs",0);this._callbacks=t}start(t,e,i,r){this.stop();const s=()=>{if(r()){this._raf=null;return}let a;try{a=t.time()}catch{this._raf=null;return}const l=i();l>0&&(a=Math.min(a,l));const p=l>0&&a>=l,m=performance.now();if((m-this._lastUpdateMs>Le||p)&&(this._lastUpdateMs=m,this._callbacks.onTimeUpdate(a,l)),p){if(this._callbacks.getLoop()){this._callbacks.restart();return}try{t.pause()}catch{}this._callbacks.onPaused(),this._raf=null;return}this._raf=requestAnimationFrame(s)};this._raf=requestAnimationFrame(s)}stop(){this._raf!==null&&(cancelAnimationFrame(this._raf),this._raf=null)}get isRunning(){return this._raf!==null}}function Pe(n){const t=Array.from(n.querySelectorAll("[data-composition-id]"));if(t.length===0)return n.body?[n.body]:[];const e=[];for(const i of t)Ie(i)||e.push(i);return Re(n),e}function Re(n){const t=n.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 r of e)r.closest("[data-composition-id]")||i.push(r);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 Ie(n){let t=n.parentElement;for(;t;){if(t.hasAttribute("data-composition-id"))return!0;t=t.parentElement}return!1}const Oe=.05,Ne=2;class De{constructor(t){h(this,"_entries",[]);h(this,"_mediaObserver");h(this,"_playbackErrorPosted",!1);h(this,"_audioOwner","runtime");h(this,"_urlAudioEntry",null);h(this,"_urlAudioSrc",null);h(this,"_dispatchEvent");h(this,"_getMuted");h(this,"_getVolume");h(this,"_getPlaybackRate");h(this,"_getCurrentTime");h(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(),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}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);const e=this._getCurrentTime()-t.start;e<0||e>=t.duration||this._playEntry(t)}_refreshEntryBounds(t){var r;if(!((r=t.source)!=null&&r.isConnected))return;const e=parseFloat(t.source.getAttribute("data-start")||"0");t.start=Number.isFinite(e)?e:0;const i=parseFloat(t.source.getAttribute("data-duration")||"");t.duration=Number.isFinite(i)&&i>0?i:Number.POSITIVE_INFINITY}_gateEntryPlayback(t,e){return e<0||e>=t.duration?(t.el.paused||t.el.pause(),t.driftSamples=0,!1):(this._audioOwner==="parent"&&!this._isPaused()&&t.el.paused&&this._playEntry(t),!0)}playAll(){for(const t of this._entries)this._playEntryIfActive(t)}pauseAll(){for(const t of this._entries)t.el.pause()}seekAll(t){for(const e of this._entries){this._refreshEntryBounds(e);const i=t-e.start;i>=0&&i<e.duration&&(e.el.currentTime=i)}}mirrorTime(t,e){const i=(e==null?void 0:e.force)===!0;for(const r of this._entries){this._refreshEntryBounds(r);const s=t-r.start;this._gateEntryPlayback(r,s)&&(Math.abs(r.el.currentTime-s)>Oe?(r.driftSamples+=1,(i||r.driftSamples>=Ne)&&(r.el.currentTime=s,r.driftSamples=0)):r.driftSamples=0)}}promoteToParentProxy(t,e){if(this._audioOwner==="parent")return;if(this._audioOwner="parent",t)for(const r of t.querySelectorAll("video, audio"))r.muted=!0;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)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=e?t:null,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,r,s){if(this._entries.some(m=>m.el.src===t))return null;const a=e==="video"?document.createElement("video"):new Audio;a.preload="auto",a.src=t,a.load(),a.muted=this._getMuted(),a.volume=this._getVolume();const l=this._getPlaybackRate();l!==1&&(a.playbackRate=l);const p={el:a,start:i,duration:r,driftSamples:0,source:s};return 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")return;const e=this._resolveIframeMediaSrc(t);if(!e)return;const i=parseFloat(t.getAttribute("data-start")||"0"),r=parseFloat(t.getAttribute("data-duration")||"Infinity"),s=t.tagName==="VIDEO"?"video":"audio",a=this._createEntry(e,s,i,r,t);a&&this._audioOwner==="parent"&&(this.mirrorTime(this._getCurrentTime(),{force:!0}),this._isPaused()||this._playEntryIfActive(a))}_detachIframeMedia(t){const e=this._resolveIframeMediaSrc(t);if(!e)return;const i=this._entries.findIndex(s=>s.el.src===e);if(i===-1)return;const r=this._entries[i];r.el.pause(),r.el.src="",this._entries.splice(i,1)}_observeDynamicMedia(t){if(this.teardownObserver(),typeof MutationObserver>"u"||!t.body)return;const e=new MutationObserver(s=>{var a,l,p,m;for(const u of s){if(u.type==="attributes"&&u.attributeName==="preload"){const c=u.target;c instanceof HTMLMediaElement&&c.matches("audio[data-start], video[data-start]")&&c.preload==="auto"&&this._adoptIframeMedia(c);continue}for(const c of u.addedNodes){if(!(c instanceof Element))continue;const g=[];(a=c.matches)!=null&&a.call(c,"audio[data-start], video[data-start]")&&g.push(c);const f=(l=c.querySelectorAll)==null?void 0:l.call(c,"audio[data-start], video[data-start]");if(f)for(const b of f)g.push(b);for(const b of g)this._adoptIframeMedia(b)}for(const c of u.removedNodes){if(!(c instanceof Element))continue;const g=[];(p=c.matches)!=null&&p.call(c,"audio[data-start], video[data-start]")&&g.push(c);const f=(m=c.querySelectorAll)==null?void 0:m.call(c,"audio[data-start], video[data-start]");if(f)for(const b of f)g.push(b);for(const b of g)this._detachIframeMedia(b)}}}),i={childList:!0,subtree:!0,attributes:!0,attributeFilter:["preload"]},r=Pe(t);for(const s of r)e.observe(s,i);this._mediaObserver=e}}const Fe=100;function Ue(n,t,e,i){const r=(n.frame??0)/t,s=e.duration>0?Math.min(r,e.duration):r,a=!e.paused,l=!n.isPlaying,p=e.duration>0&&s>=e.duration&&(a||n.isPlaying);if(p&&i.getLoop())return i.media.audioOwner==="parent"&&i.media.pauseAll(),i.seek(0),i.play(),{...e,currentTime:s,paused:!1};const m={...e,currentTime:s,paused:l};i.media.audioOwner==="parent"&&(a&&l?i.media.pauseAll():!a&&!l&&i.media.playAll(),i.media.mirrorTime(s));const u=performance.now(),c=l!==e.paused;return(u-e.lastUpdateMs>Fe||c)&&(m.lastUpdateMs=u,i.updateControlsTime(s,e.duration),i.updateControlsPlaying(!l),i.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:s}}))),p&&(i.media.audioOwner==="parent"&&i.media.pauseAll(),m.paused=!0,i.updateControlsPlaying(!1),i.dispatchEvent(new Event("ended"))),m}const de=30;function He(n){return Array.isArray(n)?n.filter(t=>typeof t=="object"&&t!==null&&typeof t.id=="string"&&typeof t.start=="number"&&typeof t.duration=="number"):[]}function Ve(n,t,e){if(n.source!==t)return;const i=n.data;if(!(!i||i.source!=="hf-preview")){if(i.type==="shader-transition-state"){const r=i.state&&typeof i.state=="object"?i.state:{};e.shaderLoader.update(r,e.getShaderLoadingMode()),e.dispatchEvent(new CustomEvent("shadertransitionstate",{detail:{compositionId:i.compositionId,state:r}}));return}if(i.type==="ready"){e.onRuntimeReady();return}if(i.type==="state"){e.setPlaybackState(Ue({frame:i.frame??0,isPlaying:!!i.isPlaying},de,e.getPlaybackState(),e));return}if(i.type==="media-autoplay-blocked"){let r=null;try{r=e.getIframeDoc()}catch{}e.media.promoteToParentProxy(r,(s,a)=>e.media.mirrorTime(s,a)),e.sendControl("set-media-output-muted",{muted:!0});return}if(i.type==="timeline"&&i.durationInFrames>0){if(Number.isFinite(i.durationInFrames)){const r=e.getPlaybackState(),s=i.durationInFrames/de;e.setPlaybackState({...r,duration:s}),e.updateControlsTime(r.currentTime,s)}e.setScenes(He(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)}}const T="shader-capture-scale",x="shader-loading",$e="__hf_shader_capture_scale",ze="__hf_shader_loading",N=["Preparing scene transitions","Sampling outgoing scene motion","Sampling incoming scene motion","Caching transition frames","Finalizing transition preview"];function z(n){if(n===null)return null;const t=Number(n);return!Number.isFinite(t)||t<=0?null:String(Math.min(1,Math.max(.25,t)))}function je(n){if(n===null||n.trim()==="")return"composition";const t=n.trim().toLowerCase();return t==="none"||t==="false"||t==="0"||t==="off"?"none":t==="player"||t==="true"||t==="1"||t==="on"?"player":"composition"}function le(n,t,e){e===null?n.delete(t):n.set(t,e)}function Be(n,t,e){const i=n.indexOf("#"),r=i>=0?n.slice(0,i):n,s=i>=0?n.slice(i):"",a=r.indexOf("?"),l=a>=0?r.slice(0,a):r,p=a>=0?r.slice(a+1):"",m=new URLSearchParams(p);le(m,$e,t),le(m,ze,e==="composition"?null:e);const u=m.toString();return`${l}${u?`?${u}`:""}${s}`}function We(n,t,e){if(t===null&&e==="composition")return n;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 r=`<script data-hyperframes-player-shader-options>${i.join("")}<\/script>`;return/<head\b[^>]*>/i.test(n)?n.replace(/<head\b[^>]*>/i,s=>`${s}${r}`):/<html\b[^>]*>/i.test(n)?n.replace(/<html\b[^>]*>/i,s=>`${s}${r}`):`${r}${n}`}function S(n){return je(n.getAttribute(x))}function qe(n){return Number(z(n.getAttribute(T))??"1")}function H(n,t){return Be(t,z(n.getAttribute(T)),S(n))}function V(n,t){return We(t,z(n.getAttribute(T)),S(n))}function Ge(){const n=document.createElement("div");n.className="hfp-shader-loader",n.setAttribute("role","status"),n.setAttribute("aria-live","polite"),n.setAttribute("aria-label","Preparing scene transitions"),n.setAttribute("data-hyperframes-ignore",""),n.draggable=!1;const t=f=>{f.preventDefault(),f.stopPropagation()};for(const f of["selectstart","dragstart","pointerdown","mousedown","click","dblclick","contextmenu","touchstart"])n.addEventListener(f,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 r=document.createElement("div");r.className="hfp-shader-loader-title";const s=document.createElement("span");s.className="hfp-shader-loader-title-text",s.textContent=N[0],r.appendChild(s);const a=document.createElement("div");a.className="hfp-shader-loader-detail",a.textContent="Rendering animated scene samples for shader transitions.";const l=document.createElement("div");l.className="hfp-shader-loader-track",l.setAttribute("aria-hidden","true");const p=document.createElement("div");p.className="hfp-shader-loader-fill",l.appendChild(p);const m=document.createElement("div");m.className="hfp-shader-loader-progress";const u=f=>{const b=document.createElement("div");b.className="hfp-shader-loader-row";const _=document.createElement("span");_.className="hfp-shader-loader-label",_.textContent=f;const y=document.createElement("span");return y.className="hfp-shader-loader-value",b.appendChild(_),b.appendChild(y),m.appendChild(b),{row:b,label:_,value:y}},c=u("transition"),g=u("transition frame");return e.appendChild(i),e.appendChild(r),e.appendChild(a),e.appendChild(l),e.appendChild(m),n.appendChild(e),{root:n,fill:p,title:s,detail:a,transitionValue:c.value,frameLabel:g.label,frameValue:g.value,frameRow:g.row}}const Xe=420;class Ye{constructor(t){h(this,"_el");h(this,"_hideTimeout",null);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())}reset(){this._hideTimeout&&(clearTimeout(this._hideTimeout),this._hideTimeout=null),this._el.root.classList.remove("hfp-visible","hfp-hiding"),this._el.fill.style.transform="scaleX(0)",this._el.transitionValue.textContent="",this._el.frameValue.textContent="",this._el.frameRow.style.visibility="hidden"}update(t,e){if(e!=="player"){this.reset();return}if(t.ready||!t.loading){this.hide();return}const i=typeof t.progress=="number"&&Number.isFinite(t.progress)?t.progress:0,r=typeof t.total=="number"&&Number.isFinite(t.total)?t.total:0,s=r>0?Math.min(1,Math.max(0,i/r)):0,a=Math.min(N.length-1,Math.floor(s*N.length));this._el.title.textContent=N[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(${s})`,this._el.transitionValue.textContent=t.currentTransition!==void 0&&t.transitionTotal!==void 0?`${t.currentTransition}/${t.transitionTotal}`:r>0?`${i}/${r}`:"";const l=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.frameValue.textContent=l,this._el.frameRow.style.visibility=l?"visible":"hidden",this._el.root.setAttribute("aria-valuenow",String(Math.round(s*100))),this.show()}get hideTimeout(){return this._hideTimeout}destroy(){this._hideTimeout&&(clearTimeout(this._hideTimeout),this._hideTimeout=null)}_scheduleCleanup(){this._hideTimeout&&clearTimeout(this._hideTimeout),this._hideTimeout=setTimeout(()=>{this._el.root.classList.remove("hfp-hiding"),this._hideTimeout=null},Xe)}}const Qe=.1,Je=5;function $(n){return!Number.isFinite(n)||n<=0?1:Math.max(Qe,Math.min(Je,n))}class Ke extends HTMLElement{constructor(){super();h(this,"shadow");h(this,"container");h(this,"iframe");h(this,"posterEl",null);h(this,"controlsApi",null);h(this,"resizeObserver");h(this,"shaderLoader");h(this,"probe");h(this,"_ready",!1);h(this,"_currentTime",0);h(this,"_duration",0);h(this,"_paused",!0);h(this,"_lastUpdateMs",0);h(this,"_volume",1);h(this,"_compositionWidth",1920);h(this,"_compositionHeight",1080);h(this,"_directTimelineAdapter",null);h(this,"_directTimelineClock");h(this,"_parentTickRaf",null);h(this,"_media");h(this,"_scenes",[]);this.shadow=this.attachShadow({mode:"open"}),ke(this.shadow,ve),{container:this.container,iframe:this.iframe}=xe(),this.shadow.appendChild(this.container);const e=Ge();this.shadow.appendChild(e.root),this.shaderLoader=new Ye(e),this._media=new De({dispatchEvent:i=>this.dispatchEvent(i),getMuted:()=>this.muted,getVolume:()=>this._volume,getPlaybackRate:()=>this.playbackRate,getCurrentTime:()=>this._currentTime,isPaused:()=>this._paused}),this._directTimelineClock=new Me({onTimeUpdate:(i,r)=>{var s;this._currentTime=i,(s=this.controlsApi)==null||s.updateTime(i,r),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:i}}))},getLoop:()=>this.loop,restart:()=>{this.seek(0),this.play()},onPaused:()=>{var i;this._media.audioOwner==="parent"&&this._media.pauseAll(),this._paused=!0,(i=this.controlsApi)==null||i.updatePlaying(!1),this.dispatchEvent(new Event("ended"))},onEnded:()=>this.loop}),this.probe=new be(this.iframe,{onReady:i=>this._onProbeReady(i),onError:i=>this.dispatchEvent(new CustomEvent("error",{detail:{message:i}}))}),this.addEventListener("click",i=>{Te(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)}static get observedAttributes(){return["src","srcdoc","width","height","controls","muted","audio-locked","volume","poster","playback-rate","audio-src",T,x]}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.posterEl=ae(this.shadow,this.getAttribute("poster"),this.posterEl)),this.hasAttribute("audio-src")&&this._media.setupFromUrl(this.getAttribute("audio-src")),this.hasAttribute("srcdoc")&&(this.iframe.srcdoc=V(this,this.getAttribute("srcdoc"))),this.hasAttribute("src")&&(this.iframe.src=H(this,this.getAttribute("src"))),!this.hasAttribute("audio-locked")&&this._isLockedHostEnvironment()&&this._applyAudioLock(!0)}disconnectedCallback(){var e;this.resizeObserver.disconnect(),window.removeEventListener("message",this._onMessage),this.iframe.removeEventListener("load",this._onIframeLoad),this.probe.stop(),this._directTimelineClock.stop(),this._stopParentTickClock(),this._directTimelineAdapter=null,this.shaderLoader.destroy(),this._media.destroy(),(e=this.controlsApi)==null||e.destroy()}attributeChangedCallback(e,i,r){var s,a,l,p,m;switch(e){case"src":r&&(this._ready=!1,this.iframe.src=H(this,r));break;case"srcdoc":this._ready=!1,r!==null?this.iframe.srcdoc=V(this,r):this.iframe.removeAttribute("srcdoc");break;case"width":this._compositionWidth=F(r)??1920,this._rescale();break;case"height":this._compositionHeight=F(r)??1080,this._rescale();break;case"controls":r!==null?this._setupControls():((s=this.controlsApi)==null||s.destroy(),this.controlsApi=null);break;case"poster":this.posterEl=ae(this.shadow,r,this.posterEl);break;case"playback-rate":{const u=$(parseFloat(r||"1"));this._media.updatePlaybackRate(u),this._sendControl("set-playback-rate",{playbackRate:u}),(l=(a=this._directTimelineAdapter)==null?void 0:a.timeScale)==null||l.call(a,u),(p=this.controlsApi)==null||p.updateSpeed(u),this.dispatchEvent(new Event("ratechange"));break}case"muted":this._handleMutedChange(r);break;case"audio-locked":this._applyAudioLock(r!==null);break;case"volume":{const u=Math.max(0,Math.min(1,parseFloat(r||"1")));this._volume=u,this._media.updateVolume(u),this._sendControl("set-volume",{volume:u}),(m=this.controlsApi)==null||m.updateVolume(u),this.dispatchEvent(new Event("volumechange"));break}case"audio-src":r?this._media.setupFromUrl(r):this._media.teardownUrlAudio();break;case T:case x:this._reloadShaderOptions();break}}get iframeElement(){return this.iframe}get scenes(){return this._scenes}play(){var i,r;(i=this.posterEl)==null||i.remove(),this.posterEl=null,this._duration>0&&this._currentTime>=this._duration&&this.seek(0),this._paused=!1;const e=this._tryDirectTimelinePlay();e||(this._sendControl("play"),this._ready&&!this._directTimelineAdapter&&this._startParentTickClock()),this._media.audioOwner==="parent"&&this._media.playAll(),(r=this.controlsApi)==null||r.updatePlaying(!0),this.dispatchEvent(new Event("play")),e&&this._directTimelineAdapter&&this._directTimelineClock.start(this._directTimelineAdapter,()=>this._currentTime,()=>this._duration,()=>this._paused)}pause(){var e;this._tryDirectTimelinePause()||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.dispatchEvent(new Event("pause"))}seek(e){var i,r;!this._trySyncSeek(e)&&!this._tryDirectTimelineSeek(e)&&this._sendControl("seek",{frame:Math.round(e*30)}),this._directTimelineClock.stop(),this._stopParentTickClock(),this._currentTime=e,this._media.audioOwner==="parent"&&(this._media.pauseAll(),this._media.seekAll(e)),this._paused=!0,(i=this.controlsApi)==null||i.updatePlaying(!1),(r=this.controlsApi)==null||r.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}})}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 qe(this)}set shaderCaptureScale(e){this.setAttribute(T,String(e))}get shaderLoading(){return S(this)}set shaderLoading(e){e==="composition"?this.removeAttribute(x):this.setAttribute(x,e)}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()}_handleMutedChange(e){var i;if(e===null&&this._isAudioLocked()){this.setAttribute("muted","");return}this._media.updateMuted(e!==null),this._sendControl("set-muted",{muted:e!==null}),(i=this.controlsApi)==null||i.updateMuted(e!==null),this.dispatchEvent(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 loop(){return this.hasAttribute("loop")}set loop(e){e?this.setAttribute("loop",""):this.removeAttribute("loop")}_sendControl(e,i={}){var r;try{(r=this.iframe.contentWindow)==null||r.postMessage({source:"hf-parent",type:"control",action:e,...i},"*")}catch{}}_replayBridgeState(){this._sendControl("set-muted",{muted:this.muted}),this._sendControl("set-volume",{volume:this._volume}),this._sendControl("set-playback-rate",{playbackRate:this.playbackRate})}_reloadShaderOptions(){if(S(this)!=="player"&&this.shaderLoader.reset(),this.hasAttribute("srcdoc")){this.iframe.srcdoc=V(this,this.getAttribute("srcdoc")||"");return}this.hasAttribute("src")&&(this.iframe.src=H(this,this.getAttribute("src")||""))}_trySyncSeek(e){try{const i=this.iframe.contentWindow,r=i==null?void 0:i.__player;return typeof(r==null?void 0:r.seek)!="function"?!1:(r.seek.call(r,e),!0)}catch{return!1}}_withDirectTimeline(e){const i=this._directTimelineAdapter||this.probe.resolveDirectTimelineAdapter();if(!i)return!1;try{return e(i),this._directTimelineAdapter=i,!0}catch{return!1}}_tryDirectTimelineSeek(e){return this._withDirectTimeline(i=>{i.seek(e),i.pause()})}_tryDirectTimelinePlay(){return this._withDirectTimeline(e=>void e.play())}_tryDirectTimelinePause(){return this._withDirectTimeline(e=>void e.pause())}_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){Ve(e,this.iframe.contentWindow,{getPlaybackState:()=>({currentTime:this._currentTime,duration:this._duration,paused:this._paused,lastUpdateMs:this._lastUpdateMs}),setPlaybackState:({currentTime:i,duration:r,paused:s,lastUpdateMs:a})=>{this._currentTime=i,this._duration=r,this._paused=s,this._lastUpdateMs=a},getShaderLoadingMode:()=>S(this),shaderLoader:this.shaderLoader,setCompositionSize:(i,r)=>{this._compositionWidth=i,this._compositionHeight=r,this._rescale()},sendControl:(i,r)=>this._sendControl(i,r),getIframeDoc:()=>this.iframe.contentDocument,onRuntimeReady:()=>this._replayBridgeState(),setScenes:i=>{this._scenes=i,this.dispatchEvent(new CustomEvent("scenes",{detail:{scenes:i}}))},updateControlsTime:(i,r)=>{var s;return(s=this.controlsApi)==null?void 0:s.updateTime(i,r)},updateControlsPlaying:i=>{var r;return(r=this.controlsApi)==null?void 0:r.updatePlaying(i)},dispatchEvent:i=>this.dispatchEvent(i),seek:i=>this.seek(i),play:()=>this.play(),getLoop:()=>this.loop,media:this._media})}_onProbeReady({duration:e,adapter:i,compositionSize:r}){var s;this._duration=e,this._directTimelineAdapter=i.kind==="direct-timeline"?i.timeline:null,this._ready=!0,(s=this.controlsApi)==null||s.updateTime(0,e),this.dispatchEvent(new CustomEvent("ready",{detail:{duration:e}})),r&&(this._compositionWidth=r.width,this._compositionHeight=r.height,this._rescale());try{const a=this.iframe.contentDocument;a&&this._media.setupFromIframe(a)}catch{}this.hasAttribute("autoplay")&&this.play()}_rescale(){Se(this,this.iframe,this._compositionWidth,this._compositionHeight)}_onIframeLoad(){this._directTimelineAdapter=null,this._directTimelineClock.stop(),this._stopParentTickClock(),this.shaderLoader.reset(),this._media.resetForIframeLoad(),this.probe.start()}_setupControls(){this.controlsApi||(this.controlsApi=Ce(this.shadow,this.muted,this._volume,this.getAttribute("speed-presets"),{onPlay:()=>this.play(),onPause:()=>this.pause(),onSeek:e=>this.seek(e*this._duration),onSpeedChange:e=>void(this.playbackRate=e),onMuteToggle:()=>void(this.muted=!this.muted),onVolumeChange:e=>void(this.volume=e)},this._isAudioLocked()))}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,r)=>this._mirrorParentMediaTime(i,r)),this._sendControl("set-media-output-muted",{muted:!0})}_observeDynamicMedia(e){this._media.setupFromIframe(e)}}customElements.get("hyperframes-player")||customElements.define("hyperframes-player",Ke);export{Ke as HyperframesPlayer,Ae as SPEED_PRESETS,U as formatSpeed,oe as formatTime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as P}from"./index-
|
|
1
|
+
import{g as P}from"./index-DApfviyW.js";function j(c,d){for(var s=0;s<d.length;s++){const a=d[s];if(typeof a!="string"&&!Array.isArray(a)){for(const i in a)if(i!=="default"&&!(i in c)){const l=Object.getOwnPropertyDescriptor(a,i);l&&Object.defineProperty(c,i,l.get?l:{enumerable:!0,get:()=>a[i]})}}}return Object.freeze(Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}))}var v={},w;function k(){if(w)return v;w=1,Object.defineProperty(v,"__esModule",{value:!0}),v.default=d;var c=window.OfflineAudioContext||window.webkitOfflineAudioContext;function d(e){var r=a(e);return r.start(0),[i,y,O(e.sampleRate),s].reduce(function(t,o){return o(t)},r.buffer.getChannelData(0))}function s(e){return e.sort(function(r,t){return t.count-r.count}).splice(0,5)[0].tempo}function a(e){var r=e.length,t=e.numberOfChannels,o=e.sampleRate,n=new c(t,r,o),u=n.createBufferSource();u.buffer=e;var f=n.createBiquadFilter();return f.type="lowpass",u.connect(f),f.connect(n.destination),u}function i(e){for(var r=[],t=.9,o=.3,n=15;r.length<n&&t>=o;)r=l(e,t),t-=.05;if(r.length<n)throw new Error("Could not find enough samples for a reliable detection.");return r}function l(e,r){for(var t=[],o=0,n=e.length;o<n;o+=1)e[o]>r&&(t.push(o),o+=1e4);return t}function y(e){var r=[];return e.forEach(function(t,o){for(var n=function(x){var g=e[o+x]-t,_=r.some(function(h){if(h.interval===g)return h.count+=1});_||r.push({interval:g,count:1})},u=0;u<10;u+=1)n(u)}),r}function O(e){return function(r){var t=[];return r.forEach(function(o){if(o.interval!==0){for(var n=60/(o.interval/e);n<90;)n*=2;for(;n>180;)n/=2;n=Math.round(n);var u=t.some(function(f){if(f.tempo===n)return f.count+=o.count});u||t.push({tempo:n,count:o.count})}}),t}}return v}var p,b;function q(){return b||(b=1,p=k().default),p}var m=q();const A=P(m),D=j({__proto__:null,default:A},[m]);export{D as i};
|