@hyperframes/studio 0.6.0 → 0.6.2

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.
Files changed (58) hide show
  1. package/dist/assets/hyperframes-player-CzwFysqv.js +418 -0
  2. package/dist/assets/index-hYc4aP7M.js +117 -0
  3. package/dist/index.html +1 -1
  4. package/package.json +4 -4
  5. package/src/App.tsx +2 -13
  6. package/src/captions/components/CaptionOverlay.tsx +13 -246
  7. package/src/captions/components/CaptionOverlayUtils.ts +221 -0
  8. package/src/components/StudioPreviewArea.tsx +6 -2
  9. package/src/components/editor/DomEditOverlay.tsx +88 -1007
  10. package/src/components/editor/EaseCurveEditor.tsx +221 -0
  11. package/src/components/editor/FileTree.tsx +13 -621
  12. package/src/components/editor/FileTreeIcons.tsx +128 -0
  13. package/src/components/editor/FileTreeNodes.tsx +496 -0
  14. package/src/components/editor/MotionPanel.tsx +16 -390
  15. package/src/components/editor/MotionPanelFields.tsx +185 -0
  16. package/src/components/editor/domEditOverlayGeometry.ts +211 -0
  17. package/src/components/editor/domEditOverlayGestures.ts +138 -0
  18. package/src/components/editor/domEditOverlayStartGesture.ts +155 -0
  19. package/src/components/editor/domEditing.ts +44 -1150
  20. package/src/components/editor/domEditingAgentPrompt.ts +97 -0
  21. package/src/components/editor/domEditingDom.ts +266 -0
  22. package/src/components/editor/domEditingElement.ts +329 -0
  23. package/src/components/editor/domEditingLayers.ts +460 -0
  24. package/src/components/editor/domEditingTypes.ts +125 -0
  25. package/src/components/editor/manualEdits.ts +84 -1081
  26. package/src/components/editor/manualEditsDom.ts +436 -0
  27. package/src/components/editor/manualEditsParsing.ts +280 -0
  28. package/src/components/editor/manualEditsSnapshot.ts +333 -0
  29. package/src/components/editor/manualEditsTypes.ts +141 -0
  30. package/src/components/editor/studioMotion.ts +47 -434
  31. package/src/components/editor/studioMotionOps.ts +299 -0
  32. package/src/components/editor/studioMotionTypes.ts +168 -0
  33. package/src/components/editor/useDomEditOverlayGestures.ts +393 -0
  34. package/src/components/editor/useDomEditOverlayRects.ts +207 -0
  35. package/src/components/nle/NLELayout.tsx +60 -144
  36. package/src/components/nle/useCompositionStack.ts +126 -0
  37. package/src/hooks/useToast.ts +20 -0
  38. package/src/player/components/Timeline.tsx +189 -1418
  39. package/src/player/components/TimelineCanvas.tsx +434 -0
  40. package/src/player/components/TimelineEmptyState.tsx +102 -0
  41. package/src/player/components/TimelineRuler.tsx +90 -0
  42. package/src/player/components/timelineIcons.tsx +49 -0
  43. package/src/player/components/timelineLayout.ts +215 -0
  44. package/src/player/components/timelineUtils.ts +211 -0
  45. package/src/player/components/useTimelineClipDrag.ts +388 -0
  46. package/src/player/components/useTimelinePlayhead.ts +200 -0
  47. package/src/player/components/useTimelineRangeSelection.ts +135 -0
  48. package/src/player/hooks/usePlaybackKeyboard.ts +171 -0
  49. package/src/player/hooks/useTimelinePlayer.ts +69 -1372
  50. package/src/player/hooks/useTimelineSyncCallbacks.ts +288 -0
  51. package/src/player/lib/playbackAdapter.ts +145 -0
  52. package/src/player/lib/playbackShortcuts.ts +68 -0
  53. package/src/player/lib/playbackTypes.ts +60 -0
  54. package/src/player/lib/timelineDOM.ts +373 -0
  55. package/src/player/lib/timelineElementHelpers.ts +303 -0
  56. package/src/player/lib/timelineIframeHelpers.ts +269 -0
  57. package/dist/assets/hyperframes-player-DOFETgjy.js +0 -418
  58. package/dist/assets/index-DUqUmaoH.js +0 -117
@@ -1,418 +0,0 @@
1
- var oe=Object.defineProperty;var de=(a,h,e)=>h in a?oe(a,h,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[h]=e;var m=(a,h,e)=>de(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
- min-width: 0;
251
- height: var(--hfp-scrubber-height, 4px);
252
- background: var(--hfp-scrubber-bg, rgba(255, 255, 255, 0.3));
253
- border-radius: var(--hfp-scrubber-radius, 2px);
254
- cursor: pointer;
255
- position: relative;
256
- overflow: hidden;
257
- }
258
-
259
- .hfp-scrubber:hover {
260
- height: var(--hfp-scrubber-height-hover, 6px);
261
- }
262
-
263
- .hfp-progress {
264
- position: absolute;
265
- top: 0;
266
- left: 0;
267
- height: 100%;
268
- background: var(--hfp-accent, #fff);
269
- pointer-events: none;
270
- }
271
-
272
- .hfp-time {
273
- flex-shrink: 0;
274
- font-variant-numeric: tabular-nums;
275
- opacity: 0.9;
276
- }
277
-
278
- .hfp-speed-wrap {
279
- position: relative;
280
- flex-shrink: 0;
281
- }
282
-
283
- .hfp-speed-btn {
284
- background: var(--hfp-speed-btn-bg, rgba(255, 255, 255, 0.15));
285
- border: none;
286
- border-radius: var(--hfp-speed-btn-radius, 4px);
287
- color: var(--hfp-color, #fff);
288
- cursor: pointer;
289
- font-family: var(--hfp-font, system-ui, -apple-system, sans-serif);
290
- font-size: 12px;
291
- font-variant-numeric: tabular-nums;
292
- font-weight: 600;
293
- padding: 4px 8px;
294
- min-width: 40px;
295
- text-align: center;
296
- transition: background 0.15s ease;
297
- }
298
-
299
- .hfp-speed-btn:hover {
300
- background: var(--hfp-speed-btn-bg-hover, rgba(255, 255, 255, 0.3));
301
- }
302
-
303
- .hfp-speed-menu {
304
- position: absolute;
305
- bottom: calc(100% + 8px);
306
- right: 0;
307
- background: var(--hfp-menu-bg, rgba(20, 20, 20, 0.95));
308
- backdrop-filter: blur(12px);
309
- -webkit-backdrop-filter: blur(12px);
310
- border: 1px solid var(--hfp-menu-border, rgba(255, 255, 255, 0.1));
311
- border-radius: var(--hfp-menu-radius, 8px);
312
- padding: 4px;
313
- display: flex;
314
- flex-direction: column;
315
- gap: 2px;
316
- min-width: 80px;
317
- opacity: 0;
318
- visibility: hidden;
319
- transform: translateY(4px);
320
- transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
321
- box-shadow: var(--hfp-menu-shadow, 0 8px 24px rgba(0, 0, 0, 0.4));
322
- }
323
-
324
- .hfp-speed-menu.hfp-open {
325
- opacity: 1;
326
- visibility: visible;
327
- transform: translateY(0);
328
- }
329
-
330
- .hfp-speed-option {
331
- background: none;
332
- border: none;
333
- border-radius: 4px;
334
- color: var(--hfp-menu-color, rgba(255, 255, 255, 0.7));
335
- cursor: pointer;
336
- font-family: var(--hfp-font, system-ui, -apple-system, sans-serif);
337
- font-size: 13px;
338
- font-variant-numeric: tabular-nums;
339
- padding: 6px 12px;
340
- text-align: left;
341
- transition: background 0.1s ease, color 0.1s ease;
342
- white-space: nowrap;
343
- }
344
-
345
- .hfp-speed-option:hover {
346
- background: var(--hfp-menu-hover-bg, rgba(255, 255, 255, 0.1));
347
- color: var(--hfp-color, #fff);
348
- }
349
-
350
- .hfp-speed-option.hfp-active {
351
- color: var(--hfp-accent, #fff);
352
- font-weight: 600;
353
- }
354
-
355
- .hfp-volume-wrap {
356
- position: relative;
357
- flex-shrink: 0;
358
- display: flex;
359
- align-items: center;
360
- gap: 0;
361
- }
362
-
363
- .hfp-mute-btn {
364
- background: none;
365
- border: none;
366
- color: var(--hfp-color, #fff);
367
- cursor: pointer;
368
- padding: 4px;
369
- display: flex;
370
- align-items: center;
371
- justify-content: center;
372
- width: 32px;
373
- height: 32px;
374
- flex-shrink: 0;
375
- }
376
-
377
- .hfp-mute-btn:hover {
378
- opacity: 0.8;
379
- }
380
-
381
- .hfp-mute-btn svg,
382
- .hfp-mute-btn svg * {
383
- pointer-events: none;
384
- }
385
-
386
- .hfp-volume-slider-wrap {
387
- width: 0;
388
- overflow: hidden;
389
- transition: width 0.2s ease;
390
- display: flex;
391
- align-items: center;
392
- }
393
-
394
- .hfp-volume-wrap:hover .hfp-volume-slider-wrap {
395
- width: 64px;
396
- }
397
-
398
- .hfp-volume-slider {
399
- width: 56px;
400
- height: var(--hfp-scrubber-height, 4px);
401
- background: var(--hfp-scrubber-bg, rgba(255, 255, 255, 0.3));
402
- border-radius: var(--hfp-scrubber-radius, 2px);
403
- cursor: pointer;
404
- position: relative;
405
- overflow: hidden;
406
- margin-left: 4px;
407
- margin-right: 4px;
408
- }
409
-
410
- .hfp-volume-fill {
411
- position: absolute;
412
- top: 0;
413
- left: 0;
414
- height: 100%;
415
- background: var(--hfp-accent, #fff);
416
- pointer-events: none;
417
- }
418
- `,Z='<svg width="24" height="24" viewBox="0 0 18 18" fill="currentColor"><polygon points="4,2 16,9 4,16"/></svg>',le='<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>',he='<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>',ce=[.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 pe(a,h,e={}){const t=e.speedPresets??ce,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 d=document.createElement("div");d.className="hfp-progress",d.style.width="0%",n.appendChild(d);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 _=document.createElement("div");_.className="hfp-speed-menu",_.setAttribute("role","menu");for(const s of t){const o=document.createElement("button");o.className="hfp-speed-option",o.type="button",o.setAttribute("role","menuitem"),o.dataset.speed=String(s),o.textContent=O(s),s===1&&o.classList.add("hfp-active"),_.appendChild(o)}c.appendChild(_),c.appendChild(u);const p=document.createElement("div");p.className="hfp-volume-wrap";const g=document.createElement("button");g.className="hfp-mute-btn",g.type="button",g.innerHTML=K,g.setAttribute("aria-label","Mute");const b=document.createElement("div");b.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),b.appendChild(f),p.appendChild(b),p.appendChild(g),i.appendChild(r),i.appendChild(n),i.appendChild(l),i.appendChild(p),i.appendChild(c),a.appendChild(i);let E=!1,w=!1,L=1,M=null;t.indexOf(1);const k=(s,o)=>s?he:o===0||o<.5?ee:K;r.addEventListener("click",s=>{s.stopPropagation(),E?h.onPause():h.onPlay()}),g.addEventListener("click",s=>{s.stopPropagation(),h.onMuteToggle()});let x=!1;const P=s=>{const o=f.getBoundingClientRect(),v=Math.max(0,Math.min(1,(s-o.left)/o.width));L=v,y.style.width=`${v*100}%`,f.setAttribute("aria-valuenow",String(Math.round(v*100))),w&&v>0&&h.onMuteToggle(),g.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 o=s.touches[0];o&&P(o.clientX)},{passive:!0});const $=s=>{if(x){const o=s.touches[0];o&&P(o.clientX)}},z=()=>{x=!1};document.addEventListener("touchmove",$,{passive:!0}),document.addEventListener("touchend",z);const j=.05;f.addEventListener("keydown",s=>{let o=L;if(s.key==="ArrowRight"||s.key==="ArrowUp")o=Math.min(1,L+j);else if(s.key==="ArrowLeft"||s.key==="ArrowDown")o=Math.max(0,L-j);else return;s.preventDefault(),s.stopPropagation(),L=o,y.style.width=`${o*100}%`,f.setAttribute("aria-valuenow",String(Math.round(o*100))),w&&o>0&&h.onMuteToggle(),g.innerHTML=k(w,o),h.onVolumeChange(o)});const B=s=>{for(const o of _.querySelectorAll(".hfp-speed-option"))o.classList.toggle("hfp-active",o.dataset.speed===String(s))};u.addEventListener("click",s=>{s.stopPropagation();const o=_.classList.toggle("hfp-open");u.setAttribute("aria-expanded",String(o))}),_.addEventListener("click",s=>{s.stopPropagation();const o=s.target.closest(".hfp-speed-option");if(!o)return;const v=parseFloat(o.dataset.speed);t.indexOf(v),u.textContent=O(v),B(v),_.classList.remove("hfp-open"),u.setAttribute("aria-expanded","false"),h.onSpeedChange(v)});const W=()=>{_.classList.remove("hfp-open"),u.setAttribute("aria-expanded","false")};document.addEventListener("click",W);const R=s=>{const o=n.getBoundingClientRect(),v=Math.max(0,Math.min(1,(s-o.left)/o.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 o=s.touches[0];o&&R(o.clientX)},{passive:!0});const G=s=>{if(A){const o=s.touches[0];o&&R(o.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,o){const v=o>0?Math.min(s,o):s,ne=o>0?v/o*100:0;d.style.width=`${ne}%`,l.textContent=`${te(v)} / ${te(o)}`},updatePlaying(s){E=s,r.innerHTML=s?le: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,g.innerHTML=k(s,L),g.setAttribute("aria-label",s?"Unmute":"Mute")},updateVolume(s){L=s,y.style.width=`${s*100}%`,f.setAttribute("aria-valuenow",String(Math.round(s*100))),g.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 ue(a){return a.hasRuntime||a.runtimeInjected?!1:!!(a.hasNestedCompositions||a.hasTimelines&&a.attempts>=5)}let N=null;function me(){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,fe="https://cdn.jsdelivr.net/npm/@hyperframes/core/dist/hyperframe.runtime.iife.js",C="shader-capture-scale",T="shader-loading",_e="__hf_shader_capture_scale",ge="__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 be(a,h,e){const t=a.indexOf("#"),i=t>=0?a.slice(0,t):a,r=t>=0?a.slice(t):"",n=i.indexOf("?"),d=n>=0?i.slice(0,n):i,l=n>=0?i.slice(n+1):"",c=new URLSearchParams(l);se(c,_e,h),se(c,ge,e==="composition"?null:e);const u=c.toString();return`${d}${u?`?${u}`:""}${r}`}function D(a){return typeof a=="object"&&a!==null}function ve(a){return D(a)&&typeof a.getDuration=="function"}function ye(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 we(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=me();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,d,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}),(d=this.controlsApi)==null||d.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 be(e,this._shaderCaptureScaleParam(),this._shaderLoadingMode())}_prepareSrcdoc(e){return we(e,this._shaderCaptureScaleParam(),this._shaderLoadingMode())}_reloadShaderOptions(){if(this._shaderLoadingMode()!=="player"&&this._resetShaderLoader(),this.hasAttribute("srcdoc")){this.iframe.srcdoc=this._prepareSrcdoc(this.getAttribute("srcdoc")||"");return}this.hasAttribute("src")&&(this.iframe.src=this._prepareSrc(this.getAttribute("src")||""))}_createShaderLoader(){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 d=document.createElement("span");d.className="hfp-shader-loader-title-text",d.textContent=I[0],n.appendChild(d);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 _=document.createElement("div");_.className="hfp-shader-loader-progress";const p=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),_.appendChild(y),{row:y,label:E,value:w}},g=p("transition"),b=p("transition frame");return i.appendChild(r),i.appendChild(n),i.appendChild(l),i.appendChild(c),i.appendChild(_),e.appendChild(i),{root:e,fill:u,title:d,detail:l,transitionValue:g.value,frameLabel:b.label,frameValue:b.value,frameRow:b.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 d=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=d,this.shaderLoaderFrameRowEl.style.visibility=d?"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 d,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,(d=this.controlsApi)==null||d.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],d=t[n];return ye(d)?d:null}_hasRuntimeBridge(e){return Reflect.get(e,"__hf")!==void 0||D(Reflect.get(e,"__player"))}_resolvePlaybackDurationAdapter(e){const t=Reflect.get(e,"__player");if(ve(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,d;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"){const l=(t.frame??0)/F;this._currentTime=this._duration>0?Math.min(l,this._duration):l;const c=!this._paused,u=!t.isPlaying,_=this._duration>0&&this._currentTime>=this._duration&&(c||t.isPlaying);if(_&&this.loop){this._audioOwner==="parent"&&this._pauseParentMedia(),this._paused=u,this.seek(0),this.play();return}this._paused=u,this._audioOwner==="parent"&&(c&&this._paused?this._pauseParentMedia():!c&&!this._paused&&this._playParentMedia(),this._mirrorParentMediaTime(this._currentTime));const p=performance.now();(p-this._lastUpdateMs>100||this._paused!==c)&&(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}}))),_&&(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,(d=this.controlsApi)==null||d.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 d=!!(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(ue({hasRuntime:d,hasTimelines:l,hasNestedCompositions:c,runtimeInjected:this._runtimeInjected,attempts:e})){this._injectRuntime();return}if(this._runtimeInjected&&!d)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 _=this.iframe.contentDocument,p=_==null?void 0:_.querySelector("[data-composition-id]");if(p){const g=parseInt(p.getAttribute("data-width")||"0",10),b=parseInt(p.getAttribute("data-height")||"0",10);g>0&&b>0&&(this._compositionWidth=g,this._compositionHeight=b,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=fe,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=pe(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 d of this._parentMedia){const l=e-d.start;if(l<0||l>=d.duration){d.driftSamples=0;continue}Math.abs(d.el.currentTime-l)>n?(d.driftSamples+=1,(i||d.driftSamples>=r)&&(d.el.currentTime=l,d.driftSamples=0)):d.driftSamples=0}}_promoteToParentProxy(){if(this._audioOwner!=="parent"){this._audioOwner="parent";try{const e=this.iframe.contentDocument;if(e)for(const t of e.querySelectorAll("video, audio"))t.muted=!0}catch{}this._sendControl("set-media-output-muted",{muted:!0}),this._mirrorParentMediaTime(this._currentTime,{force:!0}),this._paused||this._playParentMedia(),this.dispatchEvent(new CustomEvent("audioownershipchange",{detail:{owner:"parent",reason:"autoplay-blocked"}}))}}_createParentMedia(e,t,i,r){if(this._parentMedia.some(l=>l.el.src===e))return null;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 d={el:n,start:i,duration:r,driftSamples:0};return this._parentMedia.push(d),d}_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;if(e.preload==="metadata"||e.preload==="none")return;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"),d=e.tagName==="VIDEO"?"video":"audio",l=this._createParentMedia(i,d,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(n=>{var d,l,c,u;for(const _ of n){if(_.type==="attributes"&&_.attributeName==="preload"){const p=_.target;p instanceof HTMLMediaElement&&p.matches("audio[data-start], video[data-start]")&&p.preload==="auto"&&this._adoptIframeMedia(p);continue}for(const p of _.addedNodes){if(!(p instanceof Element))continue;const g=[];(d=p.matches)!=null&&d.call(p,"audio[data-start], video[data-start]")&&g.push(p);const b=(l=p.querySelectorAll)==null?void 0:l.call(p,"audio[data-start], video[data-start]");if(b)for(const f of b)g.push(f);for(const f of g)this._adoptIframeMedia(f)}for(const p of _.removedNodes){if(!(p instanceof Element))continue;const g=[];(c=p.matches)!=null&&c.call(p,"audio[data-start], video[data-start]")&&g.push(p);const b=(u=p.querySelectorAll)==null?void 0:u.call(p,"audio[data-start], video[data-start]");if(b)for(const f of b)g.push(f);for(const f of g)this._detachIframeMedia(f)}}}),i={childList:!0,subtree:!0,attributes:!0,attributeFilter:["preload"]},r=e.querySelectorAll("[data-composition-id]");if(r.length>0)for(const n of r)t.observe(n,i);else t.observe(e.body,i);this._mediaObserver=t}_teardownMediaObserver(){var e;(e=this._mediaObserver)==null||e.disconnect(),this._mediaObserver=void 0}_detachIframeMedia(e){var d;const t=e.getAttribute("src")||((d=e.querySelector("source"))==null?void 0:d.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,ce as SPEED_PRESETS,O as formatSpeed,te as formatTime};