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