@hyperframes/studio 0.6.0-alpha.2 → 0.6.0-alpha.4

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.
@@ -0,0 +1,417 @@
1
+ var ne=Object.defineProperty;var oe=(a,h,e)=>h in a?ne(a,h,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[h]=e;var m=(a,h,e)=>oe(a,typeof h!="symbol"?h+"":h,e);const ae=`
2
+ :host {
3
+ display: block;
4
+ position: relative;
5
+ overflow: hidden;
6
+ background: #000;
7
+ contain: layout style;
8
+ }
9
+
10
+ .hfp-container {
11
+ position: absolute;
12
+ inset: 0;
13
+ overflow: hidden;
14
+ pointer-events: none;
15
+ }
16
+
17
+
18
+ .hfp-iframe {
19
+ position: absolute;
20
+ top: 50%;
21
+ left: 50%;
22
+ border: none;
23
+ pointer-events: none;
24
+ }
25
+
26
+ .hfp-poster {
27
+ position: absolute;
28
+ inset: 0;
29
+ object-fit: contain;
30
+ z-index: 1;
31
+ pointer-events: none;
32
+ }
33
+
34
+ .hfp-shader-loader {
35
+ position: absolute;
36
+ inset: 0;
37
+ z-index: 20;
38
+ display: grid;
39
+ place-items: center;
40
+ visibility: hidden;
41
+ opacity: 0;
42
+ pointer-events: none;
43
+ background: #030504;
44
+ color: #f4f7fb;
45
+ cursor: default;
46
+ user-select: none;
47
+ -webkit-user-select: none;
48
+ transition: opacity 420ms ease-out, visibility 420ms ease-out;
49
+ }
50
+
51
+ .hfp-shader-loader.hfp-visible,
52
+ .hfp-shader-loader.hfp-hiding {
53
+ visibility: visible;
54
+ }
55
+
56
+ .hfp-shader-loader.hfp-visible {
57
+ opacity: 1;
58
+ pointer-events: auto;
59
+ }
60
+
61
+ .hfp-shader-loader.hfp-hiding {
62
+ opacity: 0;
63
+ pointer-events: none;
64
+ }
65
+
66
+ .hfp-shader-loader-panel {
67
+ display: grid;
68
+ grid-template-rows: 86px 40px 26px 12px 44px;
69
+ justify-items: center;
70
+ align-items: center;
71
+ gap: 8px;
72
+ width: min(620px, 82%);
73
+ text-align: center;
74
+ font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
75
+ }
76
+
77
+ .hfp-shader-loader-mark {
78
+ width: 86px;
79
+ height: 86px;
80
+ display: grid;
81
+ place-items: center;
82
+ overflow: visible;
83
+ }
84
+
85
+ .hfp-shader-loader-mark svg {
86
+ display: block;
87
+ overflow: visible;
88
+ filter: drop-shadow(0 0 5px rgba(79, 219, 94, 0.16));
89
+ pointer-events: none;
90
+ }
91
+
92
+ .hfp-shader-loader-title {
93
+ width: 100%;
94
+ height: 40px;
95
+ overflow: hidden;
96
+ white-space: nowrap;
97
+ text-overflow: ellipsis;
98
+ font-size: 26px;
99
+ line-height: 40px;
100
+ font-weight: 700;
101
+ letter-spacing: 0;
102
+ }
103
+
104
+ .hfp-shader-loader-title-text {
105
+ color: transparent;
106
+ background: linear-gradient(
107
+ 90deg,
108
+ rgba(244, 247, 251, 0.84) 0%,
109
+ #ffffff 42%,
110
+ #80efe4 52%,
111
+ #ffffff 62%,
112
+ rgba(244, 247, 251, 0.84) 100%
113
+ );
114
+ background-size: 220% 100%;
115
+ -webkit-background-clip: text;
116
+ background-clip: text;
117
+ animation: hfp-shader-loader-sheen 1.9s linear infinite;
118
+ }
119
+
120
+ .hfp-shader-loader-detail {
121
+ width: 100%;
122
+ height: 26px;
123
+ overflow: hidden;
124
+ white-space: nowrap;
125
+ text-overflow: ellipsis;
126
+ color: rgba(244, 247, 251, 0.62);
127
+ font-size: 15px;
128
+ line-height: 26px;
129
+ font-weight: 500;
130
+ }
131
+
132
+ .hfp-shader-loader-track {
133
+ width: min(360px, 100%);
134
+ height: 8px;
135
+ overflow: hidden;
136
+ border-radius: 999px;
137
+ background: rgba(255, 255, 255, 0.1);
138
+ }
139
+
140
+ .hfp-shader-loader-fill {
141
+ width: 100%;
142
+ height: 100%;
143
+ border-radius: inherit;
144
+ background: linear-gradient(90deg, #06e3fa, #4fdb5e);
145
+ transform: scaleX(0);
146
+ transform-origin: left center;
147
+ transition: transform 160ms ease;
148
+ }
149
+
150
+ .hfp-shader-loader-progress {
151
+ width: min(420px, 100%);
152
+ height: 44px;
153
+ display: grid;
154
+ grid-template-rows: repeat(2, 22px);
155
+ color: rgba(244, 247, 251, 0.48);
156
+ font: 600 13px/22px "IBM Plex Mono", "SF Mono", "Fira Code", "Courier New", monospace;
157
+ font-variant-numeric: tabular-nums;
158
+ }
159
+
160
+ .hfp-shader-loader-row {
161
+ display: grid;
162
+ grid-template-columns: minmax(0, 1fr) 74px;
163
+ align-items: center;
164
+ column-gap: 20px;
165
+ width: 100%;
166
+ white-space: nowrap;
167
+ }
168
+
169
+ .hfp-shader-loader-label {
170
+ min-width: 0;
171
+ overflow: hidden;
172
+ text-align: left;
173
+ text-overflow: ellipsis;
174
+ }
175
+
176
+ .hfp-shader-loader-value {
177
+ text-align: right;
178
+ }
179
+
180
+ @keyframes hfp-shader-loader-sheen {
181
+ from {
182
+ background-position: 140% 0;
183
+ }
184
+ to {
185
+ background-position: -140% 0;
186
+ }
187
+ }
188
+
189
+ /* ── Theming via CSS custom properties ──
190
+ *
191
+ * Override from outside the shadow DOM:
192
+ * hyperframes-player {
193
+ * --hfp-controls-bg: linear-gradient(transparent, rgba(0,0,0,0.9));
194
+ * --hfp-accent: #ff6b6b;
195
+ * --hfp-font: "Inter", sans-serif;
196
+ * }
197
+ */
198
+
199
+ .hfp-controls {
200
+ position: absolute;
201
+ bottom: 0;
202
+ left: 0;
203
+ right: 0;
204
+ display: flex;
205
+ align-items: center;
206
+ gap: var(--hfp-controls-gap, 12px);
207
+ padding: var(--hfp-controls-padding, 8px 16px);
208
+ background: var(--hfp-controls-bg, linear-gradient(transparent, rgba(0, 0, 0, 0.7)));
209
+ color: var(--hfp-color, #fff);
210
+ font-family: var(--hfp-font, system-ui, -apple-system, sans-serif);
211
+ font-size: var(--hfp-font-size, 13px);
212
+ z-index: 10;
213
+ pointer-events: auto;
214
+ opacity: 1;
215
+ transition: opacity 0.3s ease;
216
+ user-select: none;
217
+ }
218
+
219
+ .hfp-controls.hfp-hidden {
220
+ opacity: 0;
221
+ pointer-events: none;
222
+ }
223
+
224
+ .hfp-play-btn {
225
+ background: none;
226
+ border: none;
227
+ color: var(--hfp-color, #fff);
228
+ cursor: pointer;
229
+ padding: 8px;
230
+ display: flex;
231
+ align-items: center;
232
+ justify-content: center;
233
+ width: 40px;
234
+ height: 40px;
235
+ flex-shrink: 0;
236
+ z-index: 10;
237
+ }
238
+
239
+ .hfp-play-btn:hover {
240
+ opacity: 0.8;
241
+ }
242
+
243
+ .hfp-play-btn svg,
244
+ .hfp-play-btn svg * {
245
+ pointer-events: none;
246
+ }
247
+
248
+ .hfp-scrubber {
249
+ flex: 1;
250
+ height: var(--hfp-scrubber-height, 4px);
251
+ background: var(--hfp-scrubber-bg, rgba(255, 255, 255, 0.3));
252
+ border-radius: var(--hfp-scrubber-radius, 2px);
253
+ cursor: pointer;
254
+ position: relative;
255
+ }
256
+
257
+ .hfp-scrubber:hover {
258
+ height: var(--hfp-scrubber-height-hover, 6px);
259
+ }
260
+
261
+ .hfp-progress {
262
+ position: absolute;
263
+ top: 0;
264
+ left: 0;
265
+ height: 100%;
266
+ background: var(--hfp-accent, #fff);
267
+ border-radius: var(--hfp-scrubber-radius, 2px);
268
+ pointer-events: none;
269
+ }
270
+
271
+ .hfp-time {
272
+ flex-shrink: 0;
273
+ font-variant-numeric: tabular-nums;
274
+ opacity: 0.9;
275
+ }
276
+
277
+ .hfp-speed-wrap {
278
+ position: relative;
279
+ flex-shrink: 0;
280
+ }
281
+
282
+ .hfp-speed-btn {
283
+ background: var(--hfp-speed-btn-bg, rgba(255, 255, 255, 0.15));
284
+ border: none;
285
+ border-radius: var(--hfp-speed-btn-radius, 4px);
286
+ color: var(--hfp-color, #fff);
287
+ cursor: pointer;
288
+ font-family: var(--hfp-font, system-ui, -apple-system, sans-serif);
289
+ font-size: 12px;
290
+ font-variant-numeric: tabular-nums;
291
+ font-weight: 600;
292
+ padding: 4px 8px;
293
+ min-width: 40px;
294
+ text-align: center;
295
+ transition: background 0.15s ease;
296
+ }
297
+
298
+ .hfp-speed-btn:hover {
299
+ background: var(--hfp-speed-btn-bg-hover, rgba(255, 255, 255, 0.3));
300
+ }
301
+
302
+ .hfp-speed-menu {
303
+ position: absolute;
304
+ bottom: calc(100% + 8px);
305
+ right: 0;
306
+ background: var(--hfp-menu-bg, rgba(20, 20, 20, 0.95));
307
+ backdrop-filter: blur(12px);
308
+ -webkit-backdrop-filter: blur(12px);
309
+ border: 1px solid var(--hfp-menu-border, rgba(255, 255, 255, 0.1));
310
+ border-radius: var(--hfp-menu-radius, 8px);
311
+ padding: 4px;
312
+ display: flex;
313
+ flex-direction: column;
314
+ gap: 2px;
315
+ min-width: 80px;
316
+ opacity: 0;
317
+ visibility: hidden;
318
+ transform: translateY(4px);
319
+ transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
320
+ box-shadow: var(--hfp-menu-shadow, 0 8px 24px rgba(0, 0, 0, 0.4));
321
+ }
322
+
323
+ .hfp-speed-menu.hfp-open {
324
+ opacity: 1;
325
+ visibility: visible;
326
+ transform: translateY(0);
327
+ }
328
+
329
+ .hfp-speed-option {
330
+ background: none;
331
+ border: none;
332
+ border-radius: 4px;
333
+ color: var(--hfp-menu-color, rgba(255, 255, 255, 0.7));
334
+ cursor: pointer;
335
+ font-family: var(--hfp-font, system-ui, -apple-system, sans-serif);
336
+ font-size: 13px;
337
+ font-variant-numeric: tabular-nums;
338
+ padding: 6px 12px;
339
+ text-align: left;
340
+ transition: background 0.1s ease, color 0.1s ease;
341
+ white-space: nowrap;
342
+ }
343
+
344
+ .hfp-speed-option:hover {
345
+ background: var(--hfp-menu-hover-bg, rgba(255, 255, 255, 0.1));
346
+ color: var(--hfp-color, #fff);
347
+ }
348
+
349
+ .hfp-speed-option.hfp-active {
350
+ color: var(--hfp-accent, #fff);
351
+ font-weight: 600;
352
+ }
353
+
354
+ .hfp-volume-wrap {
355
+ position: relative;
356
+ flex-shrink: 0;
357
+ display: flex;
358
+ align-items: center;
359
+ gap: 0;
360
+ }
361
+
362
+ .hfp-mute-btn {
363
+ background: none;
364
+ border: none;
365
+ color: var(--hfp-color, #fff);
366
+ cursor: pointer;
367
+ padding: 4px;
368
+ display: flex;
369
+ align-items: center;
370
+ justify-content: center;
371
+ width: 32px;
372
+ height: 32px;
373
+ flex-shrink: 0;
374
+ }
375
+
376
+ .hfp-mute-btn:hover {
377
+ opacity: 0.8;
378
+ }
379
+
380
+ .hfp-mute-btn svg,
381
+ .hfp-mute-btn svg * {
382
+ pointer-events: none;
383
+ }
384
+
385
+ .hfp-volume-slider-wrap {
386
+ width: 0;
387
+ overflow: hidden;
388
+ transition: width 0.2s ease;
389
+ display: flex;
390
+ align-items: center;
391
+ }
392
+
393
+ .hfp-volume-wrap:hover .hfp-volume-slider-wrap {
394
+ width: 64px;
395
+ }
396
+
397
+ .hfp-volume-slider {
398
+ width: 56px;
399
+ height: var(--hfp-scrubber-height, 4px);
400
+ background: var(--hfp-scrubber-bg, rgba(255, 255, 255, 0.3));
401
+ border-radius: var(--hfp-scrubber-radius, 2px);
402
+ cursor: pointer;
403
+ position: relative;
404
+ margin-left: 4px;
405
+ margin-right: 4px;
406
+ }
407
+
408
+ .hfp-volume-fill {
409
+ position: absolute;
410
+ top: 0;
411
+ left: 0;
412
+ height: 100%;
413
+ background: var(--hfp-accent, #fff);
414
+ border-radius: var(--hfp-scrubber-radius, 2px);
415
+ pointer-events: none;
416
+ }
417
+ `,Z='<svg width="24" height="24" viewBox="0 0 18 18" fill="currentColor"><polygon points="4,2 16,9 4,16"/></svg>',de='<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>',K='<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>',ee='<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>',le='<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>',he=[.25,.5,1,1.5,2,4];function O(a){return Number.isInteger(a)?`${a}x`:`${a}x`}function te(a){if(!Number.isFinite(a)||a<0)return"0:00";const h=Math.floor(a),e=Math.floor(h/60),t=h%60;return`${e}:${t.toString().padStart(2,"0")}`}function ce(a,h,e={}){const t=e.speedPresets??he,i=document.createElement("div");i.className="hfp-controls",i.addEventListener("click",s=>{s.stopPropagation()});const r=document.createElement("button");r.className="hfp-play-btn",r.type="button",r.innerHTML=Z,r.setAttribute("aria-label","Play");const n=document.createElement("div");n.className="hfp-scrubber";const o=document.createElement("div");o.className="hfp-progress",o.style.width="0%",n.appendChild(o);const l=document.createElement("span");l.className="hfp-time",l.textContent="0:00 / 0:00";const c=document.createElement("div");c.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 p=document.createElement("div");p.className="hfp-speed-menu",p.setAttribute("role","menu");for(const s of t){const d=document.createElement("button");d.className="hfp-speed-option",d.type="button",d.setAttribute("role","menuitem"),d.dataset.speed=String(s),d.textContent=O(s),s===1&&d.classList.add("hfp-active"),p.appendChild(d)}c.appendChild(p),c.appendChild(u);const _=document.createElement("div");_.className="hfp-volume-wrap";const b=document.createElement("button");b.className="hfp-mute-btn",b.type="button",b.innerHTML=K,b.setAttribute("aria-label","Mute");const g=document.createElement("div");g.className="hfp-volume-slider-wrap";const f=document.createElement("div");f.className="hfp-volume-slider",f.setAttribute("role","slider"),f.setAttribute("aria-label","Volume"),f.setAttribute("aria-valuemin","0"),f.setAttribute("aria-valuemax","100"),f.setAttribute("aria-valuenow","100"),f.tabIndex=0;const y=document.createElement("div");y.className="hfp-volume-fill",y.style.width="100%",f.appendChild(y),g.appendChild(f),_.appendChild(g),_.appendChild(b),i.appendChild(r),i.appendChild(n),i.appendChild(l),i.appendChild(_),i.appendChild(c),a.appendChild(i);let E=!1,w=!1,L=1,M=null;t.indexOf(1);const k=(s,d)=>s?le:d===0||d<.5?ee:K;r.addEventListener("click",s=>{s.stopPropagation(),E?h.onPause():h.onPlay()}),b.addEventListener("click",s=>{s.stopPropagation(),h.onMuteToggle()});let x=!1;const P=s=>{const d=f.getBoundingClientRect(),v=Math.max(0,Math.min(1,(s-d.left)/d.width));L=v,y.style.width=`${v*100}%`,f.setAttribute("aria-valuenow",String(Math.round(v*100))),w&&v>0&&h.onMuteToggle(),b.innerHTML=k(w,v),h.onVolumeChange(v)};f.addEventListener("mousedown",s=>{s.stopPropagation(),x=!0,P(s.clientX)});const U=s=>{x&&P(s.clientX)},V=()=>{x=!1};document.addEventListener("mousemove",U),document.addEventListener("mouseup",V),f.addEventListener("touchstart",s=>{x=!0;const d=s.touches[0];d&&P(d.clientX)},{passive:!0});const $=s=>{if(x){const d=s.touches[0];d&&P(d.clientX)}},z=()=>{x=!1};document.addEventListener("touchmove",$,{passive:!0}),document.addEventListener("touchend",z);const j=.05;f.addEventListener("keydown",s=>{let d=L;if(s.key==="ArrowRight"||s.key==="ArrowUp")d=Math.min(1,L+j);else if(s.key==="ArrowLeft"||s.key==="ArrowDown")d=Math.max(0,L-j);else return;s.preventDefault(),s.stopPropagation(),L=d,y.style.width=`${d*100}%`,f.setAttribute("aria-valuenow",String(Math.round(d*100))),w&&d>0&&h.onMuteToggle(),b.innerHTML=k(w,d),h.onVolumeChange(d)});const B=s=>{for(const d of p.querySelectorAll(".hfp-speed-option"))d.classList.toggle("hfp-active",d.dataset.speed===String(s))};u.addEventListener("click",s=>{s.stopPropagation();const d=p.classList.toggle("hfp-open");u.setAttribute("aria-expanded",String(d))}),p.addEventListener("click",s=>{s.stopPropagation();const d=s.target.closest(".hfp-speed-option");if(!d)return;const v=parseFloat(d.dataset.speed);t.indexOf(v),u.textContent=O(v),B(v),p.classList.remove("hfp-open"),u.setAttribute("aria-expanded","false"),h.onSpeedChange(v)});const W=()=>{p.classList.remove("hfp-open"),u.setAttribute("aria-expanded","false")};document.addEventListener("click",W);const R=s=>{const d=n.getBoundingClientRect(),v=Math.max(0,Math.min(1,(s-d.left)/d.width));h.onSeek(v)};let A=!1;n.addEventListener("mousedown",s=>{s.stopPropagation(),A=!0,R(s.clientX)});const q=s=>{A&&R(s.clientX)},X=()=>{A=!1};document.addEventListener("mousemove",q),document.addEventListener("mouseup",X),n.addEventListener("touchstart",s=>{A=!0;const d=s.touches[0];d&&R(d.clientX)},{passive:!0});const G=s=>{if(A){const d=s.touches[0];d&&R(d.clientX)}},Q=()=>{A=!1};document.addEventListener("touchmove",G,{passive:!0}),document.addEventListener("touchend",Q);const Y=()=>{M&&clearTimeout(M),M=setTimeout(()=>{E&&i.classList.add("hfp-hidden")},3e3)},J=a instanceof ShadowRoot?a.host:a;return J.addEventListener("mousemove",()=>{i.classList.remove("hfp-hidden"),Y()}),J.addEventListener("mouseleave",()=>{E&&i.classList.add("hfp-hidden")}),{updateTime(s,d){const v=d>0?s/d*100:0;o.style.width=`${v}%`,l.textContent=`${te(s)} / ${te(d)}`},updatePlaying(s){E=s,r.innerHTML=s?de:Z,r.setAttribute("aria-label",s?"Pause":"Play"),s?Y():i.classList.remove("hfp-hidden")},updateSpeed(s){t.indexOf(s),u.textContent=O(s),B(s)},updateMuted(s){w=s,b.innerHTML=k(s,L),b.setAttribute("aria-label",s?"Unmute":"Mute")},updateVolume(s){L=s,y.style.width=`${s*100}%`,f.setAttribute("aria-valuenow",String(Math.round(s*100))),b.innerHTML=k(w,s)},show(){i.style.display=""},hide(){i.style.display="none"},destroy(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",X),document.removeEventListener("touchmove",G),document.removeEventListener("touchend",Q),document.removeEventListener("mousemove",U),document.removeEventListener("mouseup",V),document.removeEventListener("touchmove",$),document.removeEventListener("touchend",z),document.removeEventListener("click",W),M&&clearTimeout(M)}}}function pe(a){return a.hasRuntime||a.runtimeInjected?!1:!!(a.hasNestedCompositions||a.hasTimelines&&a.attempts>=5)}let N=null;function ue(){if(N)return N;if(typeof CSSStyleSheet>"u")return null;try{const a=new CSSStyleSheet;return a.replaceSync(ae),N=a,a}catch{return null}}const F=30,me="https://cdn.jsdelivr.net/npm/@hyperframes/core/dist/hyperframe.runtime.iife.js",C="shader-capture-scale",T="shader-loading",fe="__hf_shader_capture_scale",be="__hf_shader_loading",I=["Preparing scene transitions","Sampling outgoing scene motion","Sampling incoming scene motion","Caching transition frames","Finalizing transition preview"];function ie(a){if(a===null)return null;const h=Number(a);return!Number.isFinite(h)||h<=0?null:String(Math.min(1,Math.max(.25,h)))}function re(a){if(a===null||a.trim()==="")return"composition";const h=a.trim().toLowerCase();return h==="none"||h==="false"||h==="0"||h==="off"?"none":h==="player"||h==="true"||h==="1"||h==="on"?"player":"composition"}function se(a,h,e){e===null?a.delete(h):a.set(h,e)}function _e(a,h,e){const t=a.indexOf("#"),i=t>=0?a.slice(0,t):a,r=t>=0?a.slice(t):"",n=i.indexOf("?"),o=n>=0?i.slice(0,n):i,l=n>=0?i.slice(n+1):"",c=new URLSearchParams(l);se(c,fe,h),se(c,be,e==="composition"?null:e);const u=c.toString();return`${o}${u?`?${u}`:""}${r}`}function D(a){return typeof a=="object"&&a!==null}function ge(a){return D(a)&&typeof a.getDuration=="function"}function ve(a){return D(a)&&typeof a.duration=="function"&&typeof a.time=="function"&&typeof a.seek=="function"&&typeof a.play=="function"&&typeof a.pause=="function"}function ye(a,h,e){if(h===null&&e==="composition")return a;const t=[];h!==null&&t.push(`window.__HF_SHADER_CAPTURE_SCALE=${JSON.stringify(h)};`),e!=="composition"&&t.push(`window.__HF_SHADER_LOADING=${JSON.stringify(e)};`);const i=`<script data-hyperframes-player-shader-options>${t.join("")}<\/script>`;return/<head\b[^>]*>/i.test(a)?a.replace(/<head\b[^>]*>/i,r=>`${r}${i}`):/<html\b[^>]*>/i.test(a)?a.replace(/<html\b[^>]*>/i,r=>`${r}${i}`):`${i}${a}`}const S=class S extends HTMLElement{constructor(){super();m(this,"shadow");m(this,"container");m(this,"iframe");m(this,"posterEl",null);m(this,"controlsApi",null);m(this,"resizeObserver");m(this,"shaderLoaderEl");m(this,"shaderLoaderFillEl");m(this,"shaderLoaderTitleEl");m(this,"shaderLoaderDetailEl");m(this,"shaderLoaderTransitionValueEl");m(this,"shaderLoaderFrameLabelEl");m(this,"shaderLoaderFrameValueEl");m(this,"shaderLoaderFrameRowEl");m(this,"shaderLoaderHideTimeout",null);m(this,"_ready",!1);m(this,"_duration",0);m(this,"_currentTime",0);m(this,"_paused",!0);m(this,"_volume",1);m(this,"_compositionWidth",1920);m(this,"_compositionHeight",1080);m(this,"_probeInterval",null);m(this,"_lastUpdateMs",0);m(this,"_directTimelineAdapter",null);m(this,"_directTimelineRaf",null);m(this,"_parentMedia",[]);m(this,"_audioOwner","runtime");m(this,"_mediaObserver");m(this,"_playbackErrorPosted",!1);m(this,"_runtimeInjected",!1);this.shadow=this.attachShadow({mode:"open"});const e=ue();if(e)this.shadow.adoptedStyleSheets=[e];else{const i=document.createElement("style");i.textContent=ae,this.shadow.appendChild(i)}this.container=document.createElement("div"),this.container.className="hfp-container",this.iframe=document.createElement("iframe"),this.iframe.className="hfp-iframe",this.iframe.sandbox.add("allow-scripts","allow-same-origin"),this.iframe.allow="autoplay; fullscreen",this.iframe.referrerPolicy="no-referrer",this.iframe.title="HyperFrames Composition",this.container.appendChild(this.iframe),this.shadow.appendChild(this.container);const t=this._createShaderLoader();this.shaderLoaderEl=t.root,this.shaderLoaderFillEl=t.fill,this.shaderLoaderTitleEl=t.title,this.shaderLoaderDetailEl=t.detail,this.shaderLoaderTransitionValueEl=t.transitionValue,this.shaderLoaderFrameLabelEl=t.frameLabel,this.shaderLoaderFrameValueEl=t.frameValue,this.shaderLoaderFrameRowEl=t.frameRow,this.shadow.appendChild(this.shaderLoaderEl),this.addEventListener("click",i=>{this._isControlsClick(i)||(this._paused?this.play():this.pause())}),this.resizeObserver=new ResizeObserver(()=>this._updateScale()),this._onMessage=this._onMessage.bind(this),this._onIframeLoad=this._onIframeLoad.bind(this)}static get observedAttributes(){return["src","srcdoc","width","height","controls","muted","volume","poster","playback-rate","audio-src",C,T]}connectedCallback(){this.resizeObserver.observe(this),window.addEventListener("message",this._onMessage),this.iframe.addEventListener("load",this._onIframeLoad),this.hasAttribute("controls")&&this._setupControls(),this.hasAttribute("poster")&&this._setupPoster(),this.hasAttribute("audio-src")&&this._setupParentAudioFromUrl(this.getAttribute("audio-src")),this.hasAttribute("srcdoc")&&(this.iframe.srcdoc=this._prepareSrcdoc(this.getAttribute("srcdoc"))),this.hasAttribute("src")&&(this.iframe.src=this._prepareSrc(this.getAttribute("src")))}disconnectedCallback(){var e;this.resizeObserver.disconnect(),window.removeEventListener("message",this._onMessage),this.iframe.removeEventListener("load",this._onIframeLoad),this._probeInterval&&clearInterval(this._probeInterval),this._stopDirectTimelineClock(),this._directTimelineAdapter=null,this.shaderLoaderHideTimeout&&clearTimeout(this.shaderLoaderHideTimeout),this.shaderLoaderHideTimeout=null,this._teardownMediaObserver(),(e=this.controlsApi)==null||e.destroy();for(const t of this._parentMedia)t.el.pause(),t.el.src="";this._parentMedia=[]}attributeChangedCallback(e,t,i){var r,n,o,l;switch(e){case"src":i&&(this._ready=!1,this.iframe.src=this._prepareSrc(i));break;case"srcdoc":this._ready=!1,i!==null?this.iframe.srcdoc=this._prepareSrcdoc(i):this.iframe.removeAttribute("srcdoc");break;case"width":this._compositionWidth=parseInt(i||"1920",10),this._updateScale();break;case"height":this._compositionHeight=parseInt(i||"1080",10),this._updateScale();break;case"controls":i!==null?this._setupControls():((r=this.controlsApi)==null||r.destroy(),this.controlsApi=null);break;case"poster":this._setupPoster();break;case"playback-rate":{const c=parseFloat(i||"1");for(const u of this._parentMedia)u.el.playbackRate=c;this._sendControl("set-playback-rate",{playbackRate:c}),(n=this.controlsApi)==null||n.updateSpeed(c),this.dispatchEvent(new Event("ratechange"));break}case"muted":for(const c of this._parentMedia)c.el.muted=i!==null;this._sendControl("set-muted",{muted:i!==null}),(o=this.controlsApi)==null||o.updateMuted(i!==null),this.dispatchEvent(new Event("volumechange"));break;case"volume":{const c=Math.max(0,Math.min(1,parseFloat(i||"1")));this._volume=c;for(const u of this._parentMedia)u.el.volume=c;this._sendControl("set-volume",{volume:c}),(l=this.controlsApi)==null||l.updateVolume(c),this.dispatchEvent(new Event("volumechange"));break}case"audio-src":i&&this._setupParentAudioFromUrl(i);break;case C:case T:this._reloadShaderOptions();break}}get iframeElement(){return this.iframe}play(){var t;this._hidePoster(),this._duration>0&&this._currentTime>=this._duration&&this.seek(0);const e=this._tryDirectTimelinePlay();e||this._sendControl("play"),this._audioOwner==="parent"&&this._playParentMedia(),this._paused=!1,(t=this.controlsApi)==null||t.updatePlaying(!0),this.dispatchEvent(new Event("play")),e&&this._startDirectTimelineClock()}pause(){var e;this._tryDirectTimelinePause()||this._sendControl("pause"),this._stopDirectTimelineClock(),this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=!0,(e=this.controlsApi)==null||e.updatePlaying(!1),this.dispatchEvent(new Event("pause"))}seek(e){var t,i;if(!this._trySyncSeek(e)&&!this._tryDirectTimelineSeek(e)){const r=Math.round(e*F);this._sendControl("seek",{frame:r})}if(this._stopDirectTimelineClock(),this._currentTime=e,this._audioOwner==="parent")for(const r of this._parentMedia){const n=e-r.start;n>=0&&n<r.duration&&(r.el.currentTime=n)}this._paused=!0,(t=this.controlsApi)==null||t.updatePlaying(!1),(i=this.controlsApi)==null||i.updateTime(this._currentTime,this._duration)}get currentTime(){return this._currentTime}set currentTime(e){this.seek(e)}get duration(){return this._duration}get paused(){return this._paused}get ready(){return this._ready}get playbackRate(){return parseFloat(this.getAttribute("playback-rate")||"1")}set playbackRate(e){this.setAttribute("playback-rate",String(e))}get shaderCaptureScale(){return Number(ie(this.getAttribute(C))??"1")}set shaderCaptureScale(e){this.setAttribute(C,String(e))}get shaderLoading(){return re(this.getAttribute(T))}set shaderLoading(e){e==="composition"?this.removeAttribute(T):this.setAttribute(T,e)}get muted(){return this.hasAttribute("muted")}set muted(e){e?this.setAttribute("muted",""):this.removeAttribute("muted")}get volume(){return this._volume}set volume(e){this.setAttribute("volume",String(Math.max(0,Math.min(1,e))))}get loop(){return this.hasAttribute("loop")}set loop(e){e?this.setAttribute("loop",""):this.removeAttribute("loop")}_sendControl(e,t={}){var i;try{(i=this.iframe.contentWindow)==null||i.postMessage({source:"hf-parent",type:"control",action:e,...t},"*")}catch{}}_shaderCaptureScaleParam(){return ie(this.getAttribute(C))}_shaderLoadingMode(){return re(this.getAttribute(T))}_prepareSrc(e){return _e(e,this._shaderCaptureScaleParam(),this._shaderLoadingMode())}_prepareSrcdoc(e){return ye(e,this._shaderCaptureScaleParam(),this._shaderLoadingMode())}_reloadShaderOptions(){if(this._shaderLoadingMode()!=="player"&&this._resetShaderLoader(),this.hasAttribute("srcdoc")){this.iframe.srcdoc=this._prepareSrcdoc(this.getAttribute("srcdoc")||"");return}this.hasAttribute("src")&&(this.iframe.src=this._prepareSrc(this.getAttribute("src")||""))}_createShaderLoader(){const e=document.createElement("div");e.className="hfp-shader-loader",e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.setAttribute("aria-label","Preparing scene transitions"),e.setAttribute("data-hyperframes-ignore",""),e.draggable=!1;const t=f=>{f.preventDefault(),f.stopPropagation()};for(const f of["selectstart","dragstart","pointerdown","mousedown","click","dblclick","contextmenu","touchstart"])e.addEventListener(f,t,{capture:!0});const i=document.createElement("div");i.className="hfp-shader-loader-panel",i.draggable=!1;const r=document.createElement("div");r.className="hfp-shader-loader-mark",r.draggable=!1,r.innerHTML=['<svg width="78" height="78" viewBox="0 0 100 100" fill="none" aria-hidden="true" draggable="false">','<path d="M10.1851 57.8021L33.1145 73.8313C36.2202 75.9978 41.5173 73.5433 42.4816 69.4984L51.7611 30.4271C52.7253 26.3822 48.5802 23.9277 44.4602 26.0942L13.917 42.1235C6.96677 45.7676 4.97564 54.1579 10.1851 57.8021Z" fill="url(#hfp-shader-loader-grad-left)"/>','<path d="M87.5129 57.5141L56.9696 73.5433C52.8371 75.7098 48.7046 73.2553 49.6688 69.2104L58.9483 30.1391C59.9125 26.0942 65.2097 23.6397 68.3154 25.8062L91.2447 41.8354C96.4668 45.4796 94.4631 53.8699 87.5129 57.5141Z" fill="url(#hfp-shader-loader-grad-right)"/>',"<defs>",'<linearGradient id="hfp-shader-loader-grad-left" x1="48.5676" y1="25" x2="44.7804" y2="71.9384" gradientUnits="userSpaceOnUse">','<stop stop-color="#06E3FA"/>','<stop offset="1" stop-color="#4FDB5E"/>',"</linearGradient>",'<linearGradient id="hfp-shader-loader-grad-right" x1="54.8282" y1="73.8392" x2="72.0989" y2="32.8932" gradientUnits="userSpaceOnUse">','<stop stop-color="#06E3FA"/>','<stop offset="1" stop-color="#4FDB5E"/>',"</linearGradient>","</defs>","</svg>"].join("");const n=document.createElement("div");n.className="hfp-shader-loader-title";const o=document.createElement("span");o.className="hfp-shader-loader-title-text",o.textContent=I[0],n.appendChild(o);const l=document.createElement("div");l.className="hfp-shader-loader-detail",l.textContent="Rendering animated scene samples for shader transitions.";const c=document.createElement("div");c.className="hfp-shader-loader-track",c.setAttribute("aria-hidden","true");const u=document.createElement("div");u.className="hfp-shader-loader-fill",c.appendChild(u);const p=document.createElement("div");p.className="hfp-shader-loader-progress";const _=f=>{const y=document.createElement("div");y.className="hfp-shader-loader-row";const E=document.createElement("span");E.className="hfp-shader-loader-label",E.textContent=f;const w=document.createElement("span");return w.className="hfp-shader-loader-value",y.appendChild(E),y.appendChild(w),p.appendChild(y),{row:y,label:E,value:w}},b=_("transition"),g=_("transition frame");return i.appendChild(r),i.appendChild(n),i.appendChild(l),i.appendChild(c),i.appendChild(p),e.appendChild(i),{root:e,fill:u,title:o,detail:l,transitionValue:b.value,frameLabel:g.label,frameValue:g.value,frameRow:g.row}}_showShaderLoader(){this.shaderLoaderHideTimeout&&(clearTimeout(this.shaderLoaderHideTimeout),this.shaderLoaderHideTimeout=null),this.shaderLoaderEl.classList.remove("hfp-hiding"),this.shaderLoaderEl.classList.add("hfp-visible")}_hideShaderLoader(){if(this.shaderLoaderEl.classList.contains("hfp-hiding")){this.shaderLoaderHideTimeout||this._scheduleShaderLoaderHideCleanup();return}this.shaderLoaderEl.classList.contains("hfp-visible")&&(this.shaderLoaderEl.classList.add("hfp-hiding"),this.shaderLoaderEl.classList.remove("hfp-visible"),this._scheduleShaderLoaderHideCleanup())}_scheduleShaderLoaderHideCleanup(){this.shaderLoaderHideTimeout&&clearTimeout(this.shaderLoaderHideTimeout),this.shaderLoaderHideTimeout=setTimeout(()=>{this.shaderLoaderEl.classList.remove("hfp-hiding"),this.shaderLoaderHideTimeout=null},420)}_resetShaderLoader(){this.shaderLoaderHideTimeout&&(clearTimeout(this.shaderLoaderHideTimeout),this.shaderLoaderHideTimeout=null),this.shaderLoaderEl.classList.remove("hfp-visible","hfp-hiding"),this.shaderLoaderFillEl.style.transform="scaleX(0)",this.shaderLoaderTransitionValueEl.textContent="",this.shaderLoaderFrameValueEl.textContent="",this.shaderLoaderFrameRowEl.style.visibility="hidden"}_updateShaderLoader(e){if(this._shaderLoadingMode()!=="player"){this._resetShaderLoader();return}if(e.ready||!e.loading){this._hideShaderLoader();return}const t=typeof e.progress=="number"&&Number.isFinite(e.progress)?e.progress:0,i=typeof e.total=="number"&&Number.isFinite(e.total)?e.total:0,r=i>0?Math.min(1,Math.max(0,t/i)):0,n=Math.min(I.length-1,Math.floor(r*I.length));this.shaderLoaderTitleEl.textContent=I[n]||"Preparing scene transitions",this.shaderLoaderDetailEl.textContent=e.phase==="cached"?"Loading cached transition frames before playback.":e.phase==="finalizing"?"Uploading transition textures for smooth playback.":"Rendering animated scene samples for shader transitions.",this.shaderLoaderFillEl.style.transform=`scaleX(${r})`,this.shaderLoaderTransitionValueEl.textContent=e.currentTransition!==void 0&&e.transitionTotal!==void 0?`${e.currentTransition}/${e.transitionTotal}`:i>0?`${t}/${i}`:"";const o=e.transitionFrame!==void 0&&e.transitionFrames!==void 0?`${e.transitionFrame}/${e.transitionFrames}`:"";this.shaderLoaderFrameLabelEl.textContent=e.phase==="cached"?"cached transition frames":e.phase==="finalizing"?"finalizing transition frames":"rendering transition frames",this.shaderLoaderFrameValueEl.textContent=o,this.shaderLoaderFrameRowEl.style.visibility=o?"visible":"hidden",this.shaderLoaderEl.setAttribute("aria-valuenow",String(Math.round(r*100))),this._showShaderLoader()}_trySyncSeek(e){try{const t=this.iframe.contentWindow,i=t==null?void 0:t.__player,r=i==null?void 0:i.seek;return typeof r!="function"?!1:(r.call(i,e),!0)}catch{return!1}}_tryDirectTimelineSeek(e){const t=this._directTimelineAdapter||this._resolveDirectTimelineAdapter();if(!t)return!1;try{return t.seek(e),t.pause(),this._directTimelineAdapter=t,!0}catch{return!1}}_tryDirectTimelinePlay(){const e=this._directTimelineAdapter||this._resolveDirectTimelineAdapter();if(!e)return!1;try{return e.play(),this._directTimelineAdapter=e,!0}catch{return!1}}_tryDirectTimelinePause(){const e=this._directTimelineAdapter||this._resolveDirectTimelineAdapter();if(!e)return!1;try{return e.pause(),this._directTimelineAdapter=e,!0}catch{return!1}}_startDirectTimelineClock(){this._stopDirectTimelineClock();const e=()=>{var o,l;const t=this._directTimelineAdapter;if(!t||this._paused){this._directTimelineRaf=null;return}let i;try{i=t.time()}catch{this._directTimelineRaf=null;return}this._duration>0&&(i=Math.min(i,this._duration)),this._currentTime=i;const r=this._duration>0&&i>=this._duration,n=performance.now();if((n-this._lastUpdateMs>100||r)&&(this._lastUpdateMs=n,(o=this.controlsApi)==null||o.updateTime(this._currentTime,this._duration),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:this._currentTime}}))),r){if(this.loop){this.seek(0),this.play();return}t.pause(),this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=!0,(l=this.controlsApi)==null||l.updatePlaying(!1),this.dispatchEvent(new Event("ended")),this._directTimelineRaf=null;return}this._directTimelineRaf=requestAnimationFrame(e)};this._directTimelineRaf=requestAnimationFrame(e)}_stopDirectTimelineClock(){this._directTimelineRaf!==null&&(cancelAnimationFrame(this._directTimelineRaf),this._directTimelineRaf=null)}_resolveDirectTimelineAdapter(){try{const e=this.iframe.contentWindow;return e?this._resolveDirectTimelineAdapterFromWindow(e):null}catch{return null}}_resolveDirectTimelineAdapterFromWindow(e){var l,c;if(this._hasRuntimeBridge(e))return null;const t=Reflect.get(e,"__timelines");if(!D(t))return null;const i=Object.keys(t);if(i.length===0)return null;const r=(c=(l=this.iframe.contentDocument)==null?void 0:l.querySelector("[data-composition-id]"))==null?void 0:c.getAttribute("data-composition-id"),n=r&&r in t?r:i[i.length-1],o=t[n];return ve(o)?o:null}_hasRuntimeBridge(e){return Reflect.get(e,"__hf")!==void 0||D(Reflect.get(e,"__player"))}_resolvePlaybackDurationAdapter(e){const t=Reflect.get(e,"__player");if(ge(t))return{kind:"runtime",getDuration:()=>t.getDuration()};const i=this._resolveDirectTimelineAdapterFromWindow(e);return i?{kind:"direct-timeline",timeline:i,getDuration:()=>i.duration()}:null}_isControlsClick(e){return e.composedPath().some(t=>t instanceof HTMLElement&&t.classList.contains("hfp-controls"))}_onMessage(e){var i,r,n,o;if(e.source!==this.iframe.contentWindow)return;const t=e.data;if(!(!t||t.source!=="hf-preview")){if(t.type==="shader-transition-state"){const l=t.state&&typeof t.state=="object"?t.state:{};this._updateShaderLoader(l),this.dispatchEvent(new CustomEvent("shadertransitionstate",{detail:{compositionId:t.compositionId,state:l}}));return}if(t.type==="state"){this._currentTime=(t.frame??0)/F;const l=!this._paused,c=!t.isPlaying,u=this._duration>0&&this._currentTime>=this._duration&&(l||t.isPlaying);if(u&&this.loop){this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=c,this.seek(0),this.play();return}this._paused=c,this._audioOwner==="parent"&&(l&&this._paused?this._pauseParentMedia():!l&&!this._paused&&this._playParentMedia(),this._mirrorParentMediaTime(this._currentTime));const p=performance.now();(p-this._lastUpdateMs>100||this._paused!==l)&&(this._lastUpdateMs=p,(i=this.controlsApi)==null||i.updateTime(this._currentTime,this._duration),(r=this.controlsApi)==null||r.updatePlaying(!this._paused),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:this._currentTime}}))),u&&(this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=!0,(n=this.controlsApi)==null||n.updatePlaying(!1),this.dispatchEvent(new Event("ended")))}t.type==="media-autoplay-blocked"&&this._promoteToParentProxy(),t.type==="timeline"&&t.durationInFrames>0&&Number.isFinite(t.durationInFrames)&&(this._duration=t.durationInFrames/F,(o=this.controlsApi)==null||o.updateTime(this._currentTime,this._duration)),t.type==="stage-size"&&t.width>0&&t.height>0&&(this._compositionWidth=t.width,this._compositionHeight=t.height,this._updateScale())}}_onIframeLoad(){let e=0;this._runtimeInjected=!1,this._directTimelineAdapter=null,this._stopDirectTimelineClock(),this._resetShaderLoader();const t=this._audioOwner==="parent";this._audioOwner="runtime",this._playbackErrorPosted=!1,this._pauseParentMedia(),this._teardownMediaObserver(),t&&this.dispatchEvent(new CustomEvent("audioownershipchange",{detail:{owner:"runtime",reason:"iframe-reload"}})),this._probeInterval&&clearInterval(this._probeInterval),this._probeInterval=setInterval(()=>{var i,r;e++;try{const n=this.iframe.contentWindow;if(!n)return;const o=!!(n.__hf||n.__player),l=!!(n.__timelines&&Object.keys(n.__timelines).length>0),c=!!((i=this.iframe.contentDocument)!=null&&i.querySelector("[data-composition-src]"));if(pe({hasRuntime:o,hasTimelines:l,hasNestedCompositions:c,runtimeInjected:this._runtimeInjected,attempts:e})){this._injectRuntime();return}if(this._runtimeInjected&&!o)return;const u=this._resolvePlaybackDurationAdapter(n);if(u&&u.getDuration()>0){clearInterval(this._probeInterval),this._duration=u.getDuration(),this._directTimelineAdapter=u.kind==="direct-timeline"?u.timeline:null,this._ready=!0,(r=this.controlsApi)==null||r.updateTime(0,this._duration),this.dispatchEvent(new CustomEvent("ready",{detail:{duration:this._duration}}));const p=this.iframe.contentDocument,_=p==null?void 0:p.querySelector("[data-composition-id]");if(_){const b=parseInt(_.getAttribute("data-width")||"0",10),g=parseInt(_.getAttribute("data-height")||"0",10);b>0&&g>0&&(this._compositionWidth=b,this._compositionHeight=g,this._updateScale())}this._setupParentMedia(),this.hasAttribute("autoplay")&&this.play();return}}catch{}e>=40&&(clearInterval(this._probeInterval),this.dispatchEvent(new CustomEvent("error",{detail:{message:"Composition timeline not found after 8s"}})))},200)}_injectRuntime(){this._runtimeInjected=!0;try{const e=this.iframe.contentDocument;if(!e)return;const t=e.createElement("script");t.src=me,t.onload=()=>{},t.onerror=()=>{},(e.head||e.documentElement).appendChild(t)}catch{}}_updateScale(){const e=this.getBoundingClientRect();if(e.width===0||e.height===0)return;const t=Math.min(e.width/this._compositionWidth,e.height/this._compositionHeight);this.iframe.style.width=`${this._compositionWidth}px`,this.iframe.style.height=`${this._compositionHeight}px`,this.iframe.style.transform=`translate(-50%, -50%) scale(${t})`}_setupControls(){if(this.controlsApi)return;const e={onPlay:()=>this.play(),onPause:()=>this.pause(),onSeek:r=>this.seek(r*this._duration),onSpeedChange:r=>{this.playbackRate=r},onMuteToggle:()=>{this.muted=!this.muted},onVolumeChange:r=>{this.volume=r}},t=this.getAttribute("speed-presets"),i=t?t.split(",").map(Number).filter(r=>!isNaN(r)&&r>0):void 0;this.controlsApi=ce(this.shadow,e,{speedPresets:i}),this.controlsApi.updateMuted(this.muted),this.controlsApi.updateVolume(this._volume)}_setupPoster(){var t;const e=this.getAttribute("poster");if(!e){(t=this.posterEl)==null||t.remove(),this.posterEl=null;return}this.posterEl||(this.posterEl=document.createElement("img"),this.posterEl.className="hfp-poster",this.shadow.appendChild(this.posterEl)),this.posterEl.src=e}_playParentMedia(){for(const e of this._parentMedia)e.el.src&&e.el.play().catch(t=>this._reportPlaybackError(t))}_reportPlaybackError(e){this._playbackErrorPosted||(this._playbackErrorPosted=!0,this.dispatchEvent(new CustomEvent("playbackerror",{detail:{source:"parent-proxy",error:e}})))}_pauseParentMedia(){for(const e of this._parentMedia)e.el.pause()}_mirrorParentMediaTime(e,t){const i=(t==null?void 0:t.force)===!0,r=S.MIRROR_REQUIRED_CONSECUTIVE_DRIFT_SAMPLES,n=S.MIRROR_DRIFT_THRESHOLD_SECONDS;for(const o of this._parentMedia){const l=e-o.start;if(l<0||l>=o.duration){o.driftSamples=0;continue}Math.abs(o.el.currentTime-l)>n?(o.driftSamples+=1,(i||o.driftSamples>=r)&&(o.el.currentTime=l,o.driftSamples=0)):o.driftSamples=0}}_promoteToParentProxy(){this._audioOwner!=="parent"&&(this._audioOwner="parent",this._sendControl("set-media-output-muted",{muted:!0}),this._mirrorParentMediaTime(this._currentTime,{force:!0}),this._paused||this._playParentMedia(),this.dispatchEvent(new CustomEvent("audioownershipchange",{detail:{owner:"parent",reason:"autoplay-blocked"}})))}_createParentMedia(e,t,i,r){if(this._parentMedia.some(l=>l.el.src===e))return null;const n=t==="video"?document.createElement("video"):new Audio;n.preload="auto",n.src=e,n.load(),n.muted=this.muted,n.volume=this._volume,this.playbackRate!==1&&(n.playbackRate=this.playbackRate);const o={el:n,start:i,duration:r,driftSamples:0};return this._parentMedia.push(o),o}_setupParentAudioFromUrl(e){this._createParentMedia(e,"audio",0,1/0)}_setupParentMedia(){try{const e=this.iframe.contentDocument;if(!e)return;const t=e.querySelectorAll("audio[data-start], video[data-start]");for(const i of t)this._adoptIframeMedia(i);this._observeDynamicMedia(e)}catch{}}_adoptIframeMedia(e){var c;const t=e.getAttribute("src")||((c=e.querySelector("source"))==null?void 0:c.getAttribute("src"));if(!t)return;const i=new URL(t,e.ownerDocument.baseURI).href,r=parseFloat(e.getAttribute("data-start")||"0"),n=parseFloat(e.getAttribute("data-duration")||"Infinity"),o=e.tagName==="VIDEO"?"video":"audio",l=this._createParentMedia(i,o,r,n);l&&this._audioOwner==="parent"&&(this._mirrorParentMediaTime(this._currentTime,{force:!0}),!this._paused&&l.el.src&&l.el.play().catch(u=>this._reportPlaybackError(u)))}_observeDynamicMedia(e){if(this._teardownMediaObserver(),typeof MutationObserver>"u"||!e.body)return;const t=new MutationObserver(r=>{var n,o,l,c;for(const u of r){for(const p of u.addedNodes){if(!(p instanceof Element))continue;const _=[];(n=p.matches)!=null&&n.call(p,"audio[data-start], video[data-start]")&&_.push(p);const b=(o=p.querySelectorAll)==null?void 0:o.call(p,"audio[data-start], video[data-start]");if(b)for(const g of b)_.push(g);for(const g of _)this._adoptIframeMedia(g)}for(const p of u.removedNodes){if(!(p instanceof Element))continue;const _=[];(l=p.matches)!=null&&l.call(p,"audio[data-start], video[data-start]")&&_.push(p);const b=(c=p.querySelectorAll)==null?void 0:c.call(p,"audio[data-start], video[data-start]");if(b)for(const g of b)_.push(g);for(const g of _)this._detachIframeMedia(g)}}}),i=e.querySelectorAll("[data-composition-id]");if(i.length>0)for(const r of i)t.observe(r,{childList:!0,subtree:!0});else t.observe(e.body,{childList:!0,subtree:!0});this._mediaObserver=t}_teardownMediaObserver(){var e;(e=this._mediaObserver)==null||e.disconnect(),this._mediaObserver=void 0}_detachIframeMedia(e){var o;const t=e.getAttribute("src")||((o=e.querySelector("source"))==null?void 0:o.getAttribute("src"));if(!t)return;const i=new URL(t,e.ownerDocument.baseURI).href,r=this._parentMedia.findIndex(l=>l.el.src===i);if(r===-1)return;const n=this._parentMedia[r];n.el.pause(),n.el.src="",this._parentMedia.splice(r,1)}_hidePoster(){var e;(e=this.posterEl)==null||e.remove(),this.posterEl=null}};m(S,"MIRROR_DRIFT_THRESHOLD_SECONDS",.05),m(S,"MIRROR_REQUIRED_CONSECUTIVE_DRIFT_SAMPLES",2);let H=S;customElements.get("hyperframes-player")||customElements.define("hyperframes-player",H);export{H as HyperframesPlayer,he as SPEED_PRESETS,O as formatSpeed,te as formatTime};