hyperframes 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js
CHANGED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
var M=Object.defineProperty;var N=(a,e,t)=>e in a?M(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var l=(a,e,t)=>N(a,typeof e!="symbol"?e+"":e,t);var j=`
|
|
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
|
+
/* ── Theming via CSS custom properties ──
|
|
35
|
+
*
|
|
36
|
+
* Override from outside the shadow DOM:
|
|
37
|
+
* hyperframes-player {
|
|
38
|
+
* --hfp-controls-bg: linear-gradient(transparent, rgba(0,0,0,0.9));
|
|
39
|
+
* --hfp-accent: #ff6b6b;
|
|
40
|
+
* --hfp-font: "Inter", sans-serif;
|
|
41
|
+
* }
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
.hfp-controls {
|
|
45
|
+
position: absolute;
|
|
46
|
+
bottom: 0;
|
|
47
|
+
left: 0;
|
|
48
|
+
right: 0;
|
|
49
|
+
display: flex;
|
|
50
|
+
align-items: center;
|
|
51
|
+
gap: var(--hfp-controls-gap, 12px);
|
|
52
|
+
padding: var(--hfp-controls-padding, 8px 16px);
|
|
53
|
+
background: var(--hfp-controls-bg, linear-gradient(transparent, rgba(0, 0, 0, 0.7)));
|
|
54
|
+
color: var(--hfp-color, #fff);
|
|
55
|
+
font-family: var(--hfp-font, system-ui, -apple-system, sans-serif);
|
|
56
|
+
font-size: var(--hfp-font-size, 13px);
|
|
57
|
+
z-index: 10;
|
|
58
|
+
pointer-events: auto;
|
|
59
|
+
opacity: 1;
|
|
60
|
+
transition: opacity 0.3s ease;
|
|
61
|
+
user-select: none;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.hfp-controls.hfp-hidden {
|
|
65
|
+
opacity: 0;
|
|
66
|
+
pointer-events: none;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.hfp-play-btn {
|
|
70
|
+
background: none;
|
|
71
|
+
border: none;
|
|
72
|
+
color: var(--hfp-color, #fff);
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
padding: 8px;
|
|
75
|
+
display: flex;
|
|
76
|
+
align-items: center;
|
|
77
|
+
justify-content: center;
|
|
78
|
+
width: 40px;
|
|
79
|
+
height: 40px;
|
|
80
|
+
flex-shrink: 0;
|
|
81
|
+
z-index: 10;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.hfp-play-btn:hover {
|
|
85
|
+
opacity: 0.8;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.hfp-play-btn svg,
|
|
89
|
+
.hfp-play-btn svg * {
|
|
90
|
+
pointer-events: none;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.hfp-scrubber {
|
|
94
|
+
flex: 1;
|
|
95
|
+
height: var(--hfp-scrubber-height, 4px);
|
|
96
|
+
background: var(--hfp-scrubber-bg, rgba(255, 255, 255, 0.3));
|
|
97
|
+
border-radius: var(--hfp-scrubber-radius, 2px);
|
|
98
|
+
cursor: pointer;
|
|
99
|
+
position: relative;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.hfp-scrubber:hover {
|
|
103
|
+
height: var(--hfp-scrubber-height-hover, 6px);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.hfp-progress {
|
|
107
|
+
position: absolute;
|
|
108
|
+
top: 0;
|
|
109
|
+
left: 0;
|
|
110
|
+
height: 100%;
|
|
111
|
+
background: var(--hfp-accent, #fff);
|
|
112
|
+
border-radius: var(--hfp-scrubber-radius, 2px);
|
|
113
|
+
pointer-events: none;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.hfp-time {
|
|
117
|
+
flex-shrink: 0;
|
|
118
|
+
font-variant-numeric: tabular-nums;
|
|
119
|
+
opacity: 0.9;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.hfp-speed-wrap {
|
|
123
|
+
position: relative;
|
|
124
|
+
flex-shrink: 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.hfp-speed-btn {
|
|
128
|
+
background: var(--hfp-speed-btn-bg, rgba(255, 255, 255, 0.15));
|
|
129
|
+
border: none;
|
|
130
|
+
border-radius: var(--hfp-speed-btn-radius, 4px);
|
|
131
|
+
color: var(--hfp-color, #fff);
|
|
132
|
+
cursor: pointer;
|
|
133
|
+
font-family: var(--hfp-font, system-ui, -apple-system, sans-serif);
|
|
134
|
+
font-size: 12px;
|
|
135
|
+
font-variant-numeric: tabular-nums;
|
|
136
|
+
font-weight: 600;
|
|
137
|
+
padding: 4px 8px;
|
|
138
|
+
min-width: 40px;
|
|
139
|
+
text-align: center;
|
|
140
|
+
transition: background 0.15s ease;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.hfp-speed-btn:hover {
|
|
144
|
+
background: var(--hfp-speed-btn-bg-hover, rgba(255, 255, 255, 0.3));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.hfp-speed-menu {
|
|
148
|
+
position: absolute;
|
|
149
|
+
bottom: calc(100% + 8px);
|
|
150
|
+
right: 0;
|
|
151
|
+
background: var(--hfp-menu-bg, rgba(20, 20, 20, 0.95));
|
|
152
|
+
backdrop-filter: blur(12px);
|
|
153
|
+
-webkit-backdrop-filter: blur(12px);
|
|
154
|
+
border: 1px solid var(--hfp-menu-border, rgba(255, 255, 255, 0.1));
|
|
155
|
+
border-radius: var(--hfp-menu-radius, 8px);
|
|
156
|
+
padding: 4px;
|
|
157
|
+
display: flex;
|
|
158
|
+
flex-direction: column;
|
|
159
|
+
gap: 2px;
|
|
160
|
+
min-width: 80px;
|
|
161
|
+
opacity: 0;
|
|
162
|
+
visibility: hidden;
|
|
163
|
+
transform: translateY(4px);
|
|
164
|
+
transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
|
|
165
|
+
box-shadow: var(--hfp-menu-shadow, 0 8px 24px rgba(0, 0, 0, 0.4));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.hfp-speed-menu.hfp-open {
|
|
169
|
+
opacity: 1;
|
|
170
|
+
visibility: visible;
|
|
171
|
+
transform: translateY(0);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.hfp-speed-option {
|
|
175
|
+
background: none;
|
|
176
|
+
border: none;
|
|
177
|
+
border-radius: 4px;
|
|
178
|
+
color: var(--hfp-menu-color, rgba(255, 255, 255, 0.7));
|
|
179
|
+
cursor: pointer;
|
|
180
|
+
font-family: var(--hfp-font, system-ui, -apple-system, sans-serif);
|
|
181
|
+
font-size: 13px;
|
|
182
|
+
font-variant-numeric: tabular-nums;
|
|
183
|
+
padding: 6px 12px;
|
|
184
|
+
text-align: left;
|
|
185
|
+
transition: background 0.1s ease, color 0.1s ease;
|
|
186
|
+
white-space: nowrap;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.hfp-speed-option:hover {
|
|
190
|
+
background: var(--hfp-menu-hover-bg, rgba(255, 255, 255, 0.1));
|
|
191
|
+
color: var(--hfp-color, #fff);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.hfp-speed-option.hfp-active {
|
|
195
|
+
color: var(--hfp-accent, #fff);
|
|
196
|
+
font-weight: 600;
|
|
197
|
+
}
|
|
198
|
+
`,S='<svg width="24" height="24" viewBox="0 0 18 18" fill="currentColor"><polygon points="4,2 16,9 4,16"/></svg>',z='<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>',H=[.25,.5,1,1.5,2,4];function y(a){return Number.isInteger(a)?`${a}x`:`${a}x`}function T(a){if(!Number.isFinite(a)||a<0)return"0:00";let e=Math.floor(a),t=Math.floor(e/60),r=e%60;return`${t}:${r.toString().padStart(2,"0")}`}function O(a,e,t={}){let r=t.speedPresets??H,i=document.createElement("div");i.className="hfp-controls",i.addEventListener("click",s=>{s.stopPropagation()});let p=document.createElement("button");p.className="hfp-play-btn",p.type="button",p.innerHTML=S,p.setAttribute("aria-label","Play");let h=document.createElement("div");h.className="hfp-scrubber";let u=document.createElement("div");u.className="hfp-progress",u.style.width="0%",h.appendChild(u);let d=document.createElement("span");d.className="hfp-time",d.textContent="0:00 / 0:00";let m=document.createElement("div");m.className="hfp-speed-wrap";let o=document.createElement("button");o.className="hfp-speed-btn",o.type="button",o.textContent="1x",o.setAttribute("aria-label","Playback speed");let c=document.createElement("div");c.className="hfp-speed-menu",c.setAttribute("role","menu");for(let s of r){let n=document.createElement("button");n.className="hfp-speed-option",n.type="button",n.setAttribute("role","menuitem"),n.dataset.speed=String(s),n.textContent=y(s),s===1&&n.classList.add("hfp-active"),c.appendChild(n)}m.appendChild(c),m.appendChild(o),i.appendChild(p),i.appendChild(h),i.appendChild(d),i.appendChild(m),a.appendChild(i);let v=!1,b=null;r.indexOf(1),p.addEventListener("click",s=>{s.stopPropagation(),v?e.onPause():e.onPlay()});let E=s=>{for(let n of c.querySelectorAll(".hfp-speed-option"))n.classList.toggle("hfp-active",n.dataset.speed===String(s))};o.addEventListener("click",s=>{s.stopPropagation();let n=c.classList.toggle("hfp-open");o.setAttribute("aria-expanded",String(n))}),c.addEventListener("click",s=>{s.stopPropagation();let n=s.target.closest(".hfp-speed-option");if(!n)return;let f=parseFloat(n.dataset.speed);r.indexOf(f),o.textContent=y(f),E(f),c.classList.remove("hfp-open"),o.setAttribute("aria-expanded","false"),e.onSpeedChange(f)});let w=()=>{c.classList.remove("hfp-open"),o.setAttribute("aria-expanded","false")};document.addEventListener("click",w);let _=s=>{let n=h.getBoundingClientRect(),f=Math.max(0,Math.min(1,(s-n.left)/n.width));e.onSeek(f)},g=!1;h.addEventListener("mousedown",s=>{s.stopPropagation(),g=!0,_(s.clientX)});let k=s=>{g&&_(s.clientX)},C=()=>{g=!1};document.addEventListener("mousemove",k),document.addEventListener("mouseup",C),h.addEventListener("touchstart",s=>{g=!0;let n=s.touches[0];n&&_(n.clientX)},{passive:!0});let A=s=>{if(g){let n=s.touches[0];n&&_(n.clientX)}},L=()=>{g=!1};document.addEventListener("touchmove",A,{passive:!0}),document.addEventListener("touchend",L);let I=()=>{b&&clearTimeout(b),b=setTimeout(()=>{v&&i.classList.add("hfp-hidden")},3e3)},P=a instanceof ShadowRoot?a.host:a;return P.addEventListener("mousemove",()=>{i.classList.remove("hfp-hidden"),I()}),P.addEventListener("mouseleave",()=>{v&&i.classList.add("hfp-hidden")}),{updateTime(s,n){let f=n>0?s/n*100:0;u.style.width=`${f}%`,d.textContent=`${T(s)} / ${T(n)}`},updatePlaying(s){v=s,p.innerHTML=s?z:S,p.setAttribute("aria-label",s?"Pause":"Play"),s?I():i.classList.remove("hfp-hidden")},updateSpeed(s){r.indexOf(s),o.textContent=y(s),E(s)},show(){i.style.display=""},hide(){i.style.display="none"},destroy(){document.removeEventListener("mousemove",k),document.removeEventListener("mouseup",C),document.removeEventListener("touchmove",A),document.removeEventListener("touchend",L),document.removeEventListener("click",w),b&&clearTimeout(b)}}}var x=30,R="https://cdn.jsdelivr.net/npm/@hyperframes/core/dist/hyperframe.runtime.iife.js",D=class extends HTMLElement{constructor(){super();l(this,"shadow");l(this,"container");l(this,"iframe");l(this,"posterEl",null);l(this,"controlsApi",null);l(this,"resizeObserver");l(this,"_ready",!1);l(this,"_duration",0);l(this,"_currentTime",0);l(this,"_paused",!0);l(this,"_compositionWidth",1920);l(this,"_compositionHeight",1080);l(this,"_probeInterval",null);l(this,"_lastUpdateMs",0);l(this,"_runtimeInjected",!1);this.shadow=this.attachShadow({mode:"open"});let e=document.createElement("style");e.textContent=j,this.shadow.appendChild(e),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),this.addEventListener("click",t=>{this._isControlsClick(t)||(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","width","height","controls","muted","poster","playback-rate"]}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("src")&&(this.iframe.src=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),(e=this.controlsApi)==null||e.destroy()}attributeChangedCallback(e,t,r){var i,p;switch(e){case"src":r&&(this._ready=!1,this.iframe.src=r);break;case"width":this._compositionWidth=parseInt(r||"1920",10),this._updateScale();break;case"height":this._compositionHeight=parseInt(r||"1080",10),this._updateScale();break;case"controls":r!==null?this._setupControls():((i=this.controlsApi)==null||i.destroy(),this.controlsApi=null);break;case"poster":this._setupPoster();break;case"playback-rate":{let h=parseFloat(r||"1");this._sendControl("set-playback-rate",{playbackRate:h}),(p=this.controlsApi)==null||p.updateSpeed(h),this.dispatchEvent(new Event("ratechange"));break}case"muted":this._sendControl("set-muted",{muted:r!==null});break}}get iframeElement(){return this.iframe}play(){var e;this._hidePoster(),this._sendControl("play"),this._paused=!1,(e=this.controlsApi)==null||e.updatePlaying(!0),this.dispatchEvent(new Event("play"))}pause(){var e;this._sendControl("pause"),this._paused=!0,(e=this.controlsApi)==null||e.updatePlaying(!1),this.dispatchEvent(new Event("pause"))}seek(e){var r,i;let t=Math.round(e*x);this._sendControl("seek",{frame:t}),this._currentTime=e,this._paused=!0,(r=this.controlsApi)==null||r.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 muted(){return this.hasAttribute("muted")}set muted(e){e?this.setAttribute("muted",""):this.removeAttribute("muted")}get loop(){return this.hasAttribute("loop")}set loop(e){e?this.setAttribute("loop",""):this.removeAttribute("loop")}_sendControl(e,t={}){var r;try{(r=this.iframe.contentWindow)==null||r.postMessage({source:"hf-parent",type:"control",action:e,...t},"*")}catch{}}_isControlsClick(e){return e.composedPath().some(t=>t instanceof HTMLElement&&t.classList.contains("hfp-controls"))}_onMessage(e){var r,i,p,h;if(e.source!==this.iframe.contentWindow)return;let t=e.data;if(!(!t||t.source!=="hf-preview")){if(t.type==="state"){this._currentTime=(t.frame??0)/x;let u=!this._paused;this._paused=!t.isPlaying;let d=performance.now();(d-this._lastUpdateMs>100||this._paused!==u)&&(this._lastUpdateMs=d,(r=this.controlsApi)==null||r.updateTime(this._currentTime,this._duration),(i=this.controlsApi)==null||i.updatePlaying(!this._paused),this.dispatchEvent(new CustomEvent("timeupdate",{detail:{currentTime:this._currentTime}}))),this._currentTime>=this._duration&&!this._paused&&(this.loop?(this.seek(0),this.play()):(this._paused=!0,(p=this.controlsApi)==null||p.updatePlaying(!1),this.dispatchEvent(new Event("ended"))))}t.type==="timeline"&&t.durationInFrames>0&&Number.isFinite(t.durationInFrames)&&(this._duration=t.durationInFrames/x,(h=this.controlsApi)==null||h.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._probeInterval&&clearInterval(this._probeInterval),this._probeInterval=setInterval(()=>{var t,r;e++;try{let i=this.iframe.contentWindow;if(!i)return;let p=!!(i.__hf||i.__player),h=!!(i.__timelines&&Object.keys(i.__timelines).length>0);if(!p&&h&&!this._runtimeInjected&&e>=5){this._injectRuntime();return}if(this._runtimeInjected&&!p)return;let u=(()=>{var d,m;if(i.__player&&typeof i.__player.getDuration=="function")return i.__player;if(i.__timelines){let o=Object.keys(i.__timelines);if(o.length>0){let c=(m=(d=this.iframe.contentDocument)==null?void 0:d.querySelector("[data-composition-id]"))==null?void 0:m.getAttribute("data-composition-id"),v=c&&c in i.__timelines?c:o[o.length-1],b=i.__timelines[v];return{getDuration:()=>b.duration()}}}return null})();if(u&&u.getDuration()>0){clearInterval(this._probeInterval),this._duration=u.getDuration(),this._ready=!0,(t=this.controlsApi)==null||t.updateTime(0,this._duration),this.dispatchEvent(new CustomEvent("ready",{detail:{duration:this._duration}}));let d=(r=this.iframe.contentDocument)==null?void 0:r.querySelector("[data-composition-id]");if(d){let m=parseInt(d.getAttribute("data-width")||"0",10),o=parseInt(d.getAttribute("data-height")||"0",10);m>0&&o>0&&(this._compositionWidth=m,this._compositionHeight=o,this._updateScale())}this.hasAttribute("autoplay")&&this.play();return}}catch{}e>=40&&(clearInterval(this._probeInterval),this.dispatchEvent(new CustomEvent("error",{detail:{message:"Composition timeline not found after 8s"}})))},200)}_injectRuntime(){this._runtimeInjected=!0;try{let e=this.iframe.contentDocument;if(!e)return;let t=e.createElement("script");t.src=R,t.onload=()=>{},t.onerror=()=>{},(e.head||e.documentElement).appendChild(t)}catch{}}_updateScale(){let e=this.getBoundingClientRect();if(e.width===0||e.height===0)return;let t=Math.min(e.width/this._compositionWidth,e.height/this._compositionHeight);this.iframe.style.width=`${this._compositionWidth}px`,this.iframe.style.height=`${this._compositionHeight}px`,this.iframe.style.transform=`translate(-50%, -50%) scale(${t})`}_setupControls(){if(this.controlsApi)return;let e={onPlay:()=>this.play(),onPause:()=>this.pause(),onSeek:i=>this.seek(i*this._duration),onSpeedChange:i=>{this.playbackRate=i}},t=this.getAttribute("speed-presets"),r=t?t.split(",").map(Number).filter(i=>!isNaN(i)&&i>0):void 0;this.controlsApi=O(this.shadow,e,{speedPresets:r})}_setupPoster(){var t;let 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}_hidePoster(){var e;(e=this.posterEl)==null||e.remove(),this.posterEl=null}};customElements.get("hyperframes-player")||customElements.define("hyperframes-player",D);export{D as HyperframesPlayer,H as SPEED_PRESETS,y as formatSpeed,T as formatTime};
|