@rendiv/player 0.1.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/ErrorBoundary.d.ts +19 -0
- package/dist/ErrorBoundary.d.ts.map +1 -0
- package/dist/Player.d.ts +38 -0
- package/dist/Player.d.ts.map +1 -0
- package/dist/PlayerControls.d.ts +10 -0
- package/dist/PlayerControls.d.ts.map +1 -0
- package/dist/PlayerEmitter.d.ts +23 -0
- package/dist/PlayerEmitter.d.ts.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +289 -0
- package/dist/use-player.d.ts +17 -0
- package/dist/use-player.d.ts.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { default as React, Component, ReactNode, ErrorInfo, ComponentType } from 'react';
|
|
2
|
+
interface ErrorFallbackProps {
|
|
3
|
+
error: Error;
|
|
4
|
+
}
|
|
5
|
+
interface ErrorBoundaryProps {
|
|
6
|
+
fallback?: ComponentType<ErrorFallbackProps>;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
interface ErrorBoundaryState {
|
|
10
|
+
error: Error | null;
|
|
11
|
+
}
|
|
12
|
+
export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
13
|
+
state: ErrorBoundaryState;
|
|
14
|
+
static getDerivedStateFromError(error: Error): ErrorBoundaryState;
|
|
15
|
+
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
16
|
+
render(): string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | null | undefined;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=ErrorBoundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../src/ErrorBoundary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAE7F,UAAU,kBAAkB;IAC1B,KAAK,EAAE,KAAK,CAAC;CACd;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAC7C,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,UAAU,kBAAkB;IAC1B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED,qBAAa,aAAc,SAAQ,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IAClF,KAAK,EAAE,kBAAkB,CAAmB;IAE5C,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB;IAIjE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI;IAItD,MAAM;CA0BP"}
|
package/dist/Player.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { default as React, CSSProperties, ComponentType } from 'react';
|
|
2
|
+
import { PlayerEventMap } from './PlayerEmitter';
|
|
3
|
+
interface ErrorFallbackProps {
|
|
4
|
+
error: Error;
|
|
5
|
+
}
|
|
6
|
+
export interface PlayerProps {
|
|
7
|
+
component: ComponentType<Record<string, unknown>>;
|
|
8
|
+
durationInFrames: number;
|
|
9
|
+
fps: number;
|
|
10
|
+
compositionWidth: number;
|
|
11
|
+
compositionHeight: number;
|
|
12
|
+
style?: CSSProperties;
|
|
13
|
+
controls?: boolean;
|
|
14
|
+
loop?: boolean;
|
|
15
|
+
autoPlay?: boolean;
|
|
16
|
+
initiallyMuted?: boolean;
|
|
17
|
+
inputProps?: Record<string, unknown>;
|
|
18
|
+
playbackRate?: number;
|
|
19
|
+
errorFallback?: ComponentType<ErrorFallbackProps>;
|
|
20
|
+
}
|
|
21
|
+
type Listener<T> = (data: T) => void;
|
|
22
|
+
export interface PlayerRef {
|
|
23
|
+
play: () => void;
|
|
24
|
+
pause: () => void;
|
|
25
|
+
toggle: () => void;
|
|
26
|
+
seekTo: (frame: number) => void;
|
|
27
|
+
getCurrentFrame: () => number;
|
|
28
|
+
isPlaying: () => boolean;
|
|
29
|
+
getContainerNode: () => HTMLDivElement | null;
|
|
30
|
+
mute: () => void;
|
|
31
|
+
unmute: () => void;
|
|
32
|
+
setVolume: (v: number) => void;
|
|
33
|
+
addEventListener: <K extends keyof PlayerEventMap>(event: K, callback: Listener<PlayerEventMap[K]>) => void;
|
|
34
|
+
removeEventListener: <K extends keyof PlayerEventMap>(event: K, callback: Listener<PlayerEventMap[K]>) => void;
|
|
35
|
+
}
|
|
36
|
+
export declare const Player: React.ForwardRefExoticComponent<PlayerProps & React.RefAttributes<PlayerRef>>;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=Player.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Player.d.ts","sourceRoot":"","sources":["../src/Player.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAQZ,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AAQf,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIrE,UAAU,kBAAkB;IAC1B,KAAK,EAAE,KAAK,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAClD,gBAAgB,EAAE,MAAM,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;CACnD;AAED,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;AAErC,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,eAAe,EAAE,MAAM,MAAM,CAAC;IAC9B,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB,gBAAgB,EAAE,MAAM,cAAc,GAAG,IAAI,CAAC;IAC9C,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,SAAS,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,gBAAgB,EAAE,CAAC,CAAC,SAAS,MAAM,cAAc,EAC/C,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAClC,IAAI,CAAC;IACV,mBAAmB,EAAE,CAAC,CAAC,SAAS,MAAM,cAAc,EAClD,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAClC,IAAI,CAAC;CACX;AAED,eAAO,MAAM,MAAM,+EA2KjB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { UsePlayerReturn } from './use-player';
|
|
3
|
+
interface PlayerControlsProps {
|
|
4
|
+
player: UsePlayerReturn;
|
|
5
|
+
durationInFrames: number;
|
|
6
|
+
fps: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const PlayerControls: React.FC<PlayerControlsProps>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=PlayerControls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlayerControls.d.ts","sourceRoot":"","sources":["../src/PlayerControls.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,UAAU,mBAAmB;IAC3B,MAAM,EAAE,eAAe,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;CACb;AA2CD,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAmCxD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type PlayerEventMap = {
|
|
2
|
+
play: void;
|
|
3
|
+
pause: void;
|
|
4
|
+
ended: void;
|
|
5
|
+
frameupdate: {
|
|
6
|
+
frame: number;
|
|
7
|
+
};
|
|
8
|
+
error: {
|
|
9
|
+
error: Error;
|
|
10
|
+
};
|
|
11
|
+
fullscreenchange: {
|
|
12
|
+
isFullscreen: boolean;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
type Listener<T> = (data: T) => void;
|
|
16
|
+
export declare class PlayerEmitter {
|
|
17
|
+
private listeners;
|
|
18
|
+
addEventListener<K extends keyof PlayerEventMap>(event: K, callback: Listener<PlayerEventMap[K]>): void;
|
|
19
|
+
removeEventListener<K extends keyof PlayerEventMap>(event: K, callback: Listener<PlayerEventMap[K]>): void;
|
|
20
|
+
emit<K extends keyof PlayerEventMap>(event: K, ...args: PlayerEventMap[K] extends void ? [] : [PlayerEventMap[K]]): void;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=PlayerEmitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlayerEmitter.d.ts","sourceRoot":"","sources":["../src/PlayerEmitter.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,IAAI,CAAC;IACZ,KAAK,EAAE,IAAI,CAAC;IACZ,WAAW,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/B,KAAK,EAAE;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC;IACxB,gBAAgB,EAAE;QAAE,YAAY,EAAE,OAAO,CAAA;KAAE,CAAC;CAC7C,CAAC;AAEF,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;AAErC,qBAAa,aAAa;IACxB,OAAO,CAAC,SAAS,CAA6C;IAE9D,gBAAgB,CAAC,CAAC,SAAS,MAAM,cAAc,EAC7C,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GACpC,IAAI;IAOP,mBAAmB,CAAC,CAAC,SAAS,MAAM,cAAc,EAChD,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GACpC,IAAI;IAIP,IAAI,CAAC,CAAC,SAAS,MAAM,cAAc,EACjC,KAAK,EAAE,CAAC,EACR,GAAG,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GACjE,IAAI;CAQR"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var H=Object.defineProperty;var V=(o,r,e)=>r in o?H(o,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[r]=e;var j=(o,r,e)=>V(o,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),n=require("react"),E=require("@rendiv/core");function W(o){const{fps:r,durationInFrames:e,loop:s,playbackRate:i,autoPlay:c}=o,[g,C]=n.useState(0),[v,h]=n.useState(c),p=n.useRef(null),d=n.useRef(0),b=n.useRef(0),R=n.useCallback(()=>h(!0),[]),k=n.useCallback(()=>h(!1),[]),u=n.useCallback(()=>h(f=>!f),[]),w=n.useCallback(f=>{const t=Math.max(0,Math.min(f,e-1));b.current=t,C(t)},[e]);return n.useEffect(()=>{if(!v){p.current=null,d.current=0;return}let f;const t=1e3/(r*i),x=y=>{p.current===null&&(p.current=y);const P=y-p.current;p.current=y,d.current+=P;let m=b.current,S=!1;for(;d.current>=t;)if(d.current-=t,m+=1,S=!0,m>=e)if(s)m=0;else{m=e-1,h(!1);break}S&&(b.current=m,C(m)),f=requestAnimationFrame(x)};return f=requestAnimationFrame(x),()=>cancelAnimationFrame(f)},[v,r,i,s,e]),{frame:g,playing:v,play:R,pause:k,toggle:u,seekTo:w}}class ${constructor(){j(this,"listeners",new Map)}addEventListener(r,e){this.listeners.has(r)||this.listeners.set(r,new Set),this.listeners.get(r).add(e)}removeEventListener(r,e){var s;(s=this.listeners.get(r))==null||s.delete(e)}emit(r,...e){const s=this.listeners.get(r);if(!s)return;const i=e[0];for(const c of s)c(i)}}const O={position:"absolute",bottom:0,left:0,right:0,display:"flex",alignItems:"center",gap:8,padding:"8px 12px",backgroundColor:"rgba(0, 0, 0, 0.7)",color:"#fff",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:13,userSelect:"none"},K={background:"none",border:"none",color:"#fff",cursor:"pointer",fontSize:16,padding:"2px 6px",lineHeight:1},B={flex:1,height:4,cursor:"pointer",accentColor:"#fff"};function T(o,r){const e=o/r,s=Math.floor(e/60),i=Math.floor(e%60),c=Math.floor(e%1*100);return`${String(s).padStart(2,"0")}:${String(i).padStart(2,"0")}.${String(c).padStart(2,"0")}`}const D=({player:o,durationInFrames:r,fps:e})=>{const s=n.useCallback(i=>{o.seekTo(Number(i.target.value))},[o]);return a.jsxs("div",{style:O,children:[a.jsx("button",{type:"button",style:K,onClick:o.toggle,"aria-label":o.playing?"Pause":"Play",children:o.playing?"⏸":"▶"}),a.jsx("input",{type:"range",min:0,max:r-1,value:o.frame,onChange:s,style:B}),a.jsxs("span",{style:{minWidth:100,textAlign:"right",fontVariantNumeric:"tabular-nums"},children:[T(o.frame,e)," / ",T(r-1,e)]})]})};D.displayName="PlayerControls";class G extends n.Component{constructor(){super(...arguments);j(this,"state",{error:null})}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,s){console.error("Rendiv Player error:",e,s)}render(){if(this.state.error){const e=this.props.fallback;return e?a.jsx(e,{error:this.state.error}):a.jsx("div",{style:{padding:20,color:"#ff4444",backgroundColor:"#1a1a1a",fontFamily:"monospace",fontSize:14,whiteSpace:"pre-wrap",overflow:"auto",width:"100%",height:"100%"},children:this.state.error.message})}return this.props.children}}const L=n.forwardRef((o,r)=>{const{component:e,durationInFrames:s,fps:i,compositionWidth:c,compositionHeight:g,controls:C=!1,loop:v=!1,autoPlay:h=!1,playbackRate:p=1,inputProps:d={},style:b,errorFallback:R}=o,k=n.useRef(null),u=n.useMemo(()=>new $,[]),[w,f]=n.useState(c),t=W({fps:i,durationInFrames:s,loop:v,playbackRate:p,autoPlay:h});n.useEffect(()=>{const l=k.current;if(!l)return;const M=new ResizeObserver(N=>{for(const z of N)f(z.contentRect.width)});return M.observe(l),()=>M.disconnect()},[]),n.useEffect(()=>{u.emit("frameupdate",{frame:t.frame})},[t.frame,u]),n.useEffect(()=>{t.playing?u.emit("play"):u.emit("pause")},[t.playing,u]);const x=n.useRef(t.frame);x.current=t.frame;const y=n.useRef(t.playing);y.current=t.playing,n.useImperativeHandle(r,()=>({play:t.play,pause:t.pause,toggle:t.toggle,seekTo:t.seekTo,getCurrentFrame:()=>x.current,isPlaying:()=>y.current,getContainerNode:()=>k.current,mute:()=>{},unmute:()=>{},setVolume:()=>{},addEventListener:u.addEventListener.bind(u),removeEventListener:u.removeEventListener.bind(u)}));const P=n.useMemo(()=>({id:"player",width:c,height:g,fps:i,durationInFrames:s,defaultProps:d}),[c,g,i,s,d]),m=n.useMemo(()=>({frame:t.frame,playing:t.playing,playingRef:{current:t.playing}}),[t.frame,t.playing]),S=n.useMemo(()=>({environment:"player"}),[]),F=w/c,A=g*F,q=n.useCallback(l=>{l.key===" "||l.key==="k"?(l.preventDefault(),t.toggle()):l.key==="ArrowLeft"?(l.preventDefault(),t.seekTo(t.frame-1)):l.key==="ArrowRight"?(l.preventDefault(),t.seekTo(t.frame+1)):l.key==="0"&&(l.preventDefault(),t.seekTo(0))},[t]),I=a.jsx(G,{fallback:R,children:a.jsx(e,{...d})});return a.jsxs("div",{ref:k,style:{position:"relative",overflow:"hidden",width:"100%",height:A,backgroundColor:"#000",...b},tabIndex:0,onKeyDown:q,children:[a.jsx("div",{style:{width:c,height:g,transform:`scale(${F})`,transformOrigin:"top left",overflow:"hidden"},children:a.jsx(E.RendivEnvironmentContext.Provider,{value:S,children:a.jsx(E.CompositionContext.Provider,{value:P,children:a.jsx(E.TimelineContext.Provider,{value:m,children:I})})})}),C&&a.jsx(D,{player:t,durationInFrames:s,fps:i})]})});L.displayName="Player";exports.Player=L;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
var q = Object.defineProperty;
|
|
2
|
+
var K = (n, r, e) => r in n ? q(n, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[r] = e;
|
|
3
|
+
var D = (n, r, e) => K(n, typeof r != "symbol" ? r + "" : r, e);
|
|
4
|
+
import { jsxs as L, jsx as c } from "react/jsx-runtime";
|
|
5
|
+
import { useState as M, useRef as v, useCallback as y, useEffect as R, Component as O, forwardRef as B, useMemo as x, useImperativeHandle as G } from "react";
|
|
6
|
+
import { RendivEnvironmentContext as J, CompositionContext as Q, TimelineContext as U } from "@rendiv/core";
|
|
7
|
+
function X(n) {
|
|
8
|
+
const { fps: r, durationInFrames: e, loop: o, playbackRate: a, autoPlay: i } = n, [p, P] = M(0), [b, g] = M(i), m = v(null), u = v(0), k = v(0), F = y(() => g(!0), []), w = y(() => g(!1), []), l = y(() => g((f) => !f), []), E = y(
|
|
9
|
+
(f) => {
|
|
10
|
+
const t = Math.max(0, Math.min(f, e - 1));
|
|
11
|
+
k.current = t, P(t);
|
|
12
|
+
},
|
|
13
|
+
[e]
|
|
14
|
+
);
|
|
15
|
+
return R(() => {
|
|
16
|
+
if (!b) {
|
|
17
|
+
m.current = null, u.current = 0;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
let f;
|
|
21
|
+
const t = 1e3 / (r * a), C = (h) => {
|
|
22
|
+
m.current === null && (m.current = h);
|
|
23
|
+
const T = h - m.current;
|
|
24
|
+
m.current = h, u.current += T;
|
|
25
|
+
let d = k.current, S = !1;
|
|
26
|
+
for (; u.current >= t; )
|
|
27
|
+
if (u.current -= t, d += 1, S = !0, d >= e)
|
|
28
|
+
if (o)
|
|
29
|
+
d = 0;
|
|
30
|
+
else {
|
|
31
|
+
d = e - 1, g(!1);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
S && (k.current = d, P(d)), f = requestAnimationFrame(C);
|
|
35
|
+
};
|
|
36
|
+
return f = requestAnimationFrame(C), () => cancelAnimationFrame(f);
|
|
37
|
+
}, [b, r, a, o, e]), { frame: p, playing: b, play: F, pause: w, toggle: l, seekTo: E };
|
|
38
|
+
}
|
|
39
|
+
class Y {
|
|
40
|
+
constructor() {
|
|
41
|
+
D(this, "listeners", /* @__PURE__ */ new Map());
|
|
42
|
+
}
|
|
43
|
+
addEventListener(r, e) {
|
|
44
|
+
this.listeners.has(r) || this.listeners.set(r, /* @__PURE__ */ new Set()), this.listeners.get(r).add(e);
|
|
45
|
+
}
|
|
46
|
+
removeEventListener(r, e) {
|
|
47
|
+
var o;
|
|
48
|
+
(o = this.listeners.get(r)) == null || o.delete(e);
|
|
49
|
+
}
|
|
50
|
+
emit(r, ...e) {
|
|
51
|
+
const o = this.listeners.get(r);
|
|
52
|
+
if (!o) return;
|
|
53
|
+
const a = e[0];
|
|
54
|
+
for (const i of o)
|
|
55
|
+
i(a);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const Z = {
|
|
59
|
+
position: "absolute",
|
|
60
|
+
bottom: 0,
|
|
61
|
+
left: 0,
|
|
62
|
+
right: 0,
|
|
63
|
+
display: "flex",
|
|
64
|
+
alignItems: "center",
|
|
65
|
+
gap: 8,
|
|
66
|
+
padding: "8px 12px",
|
|
67
|
+
backgroundColor: "rgba(0, 0, 0, 0.7)",
|
|
68
|
+
color: "#fff",
|
|
69
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
70
|
+
fontSize: 13,
|
|
71
|
+
userSelect: "none"
|
|
72
|
+
}, _ = {
|
|
73
|
+
background: "none",
|
|
74
|
+
border: "none",
|
|
75
|
+
color: "#fff",
|
|
76
|
+
cursor: "pointer",
|
|
77
|
+
fontSize: 16,
|
|
78
|
+
padding: "2px 6px",
|
|
79
|
+
lineHeight: 1
|
|
80
|
+
}, ee = {
|
|
81
|
+
flex: 1,
|
|
82
|
+
height: 4,
|
|
83
|
+
cursor: "pointer",
|
|
84
|
+
accentColor: "#fff"
|
|
85
|
+
};
|
|
86
|
+
function N(n, r) {
|
|
87
|
+
const e = n / r, o = Math.floor(e / 60), a = Math.floor(e % 60), i = Math.floor(e % 1 * 100);
|
|
88
|
+
return `${String(o).padStart(2, "0")}:${String(a).padStart(2, "0")}.${String(i).padStart(2, "0")}`;
|
|
89
|
+
}
|
|
90
|
+
const z = ({
|
|
91
|
+
player: n,
|
|
92
|
+
durationInFrames: r,
|
|
93
|
+
fps: e
|
|
94
|
+
}) => {
|
|
95
|
+
const o = y(
|
|
96
|
+
(a) => {
|
|
97
|
+
n.seekTo(Number(a.target.value));
|
|
98
|
+
},
|
|
99
|
+
[n]
|
|
100
|
+
);
|
|
101
|
+
return /* @__PURE__ */ L("div", { style: Z, children: [
|
|
102
|
+
/* @__PURE__ */ c(
|
|
103
|
+
"button",
|
|
104
|
+
{
|
|
105
|
+
type: "button",
|
|
106
|
+
style: _,
|
|
107
|
+
onClick: n.toggle,
|
|
108
|
+
"aria-label": n.playing ? "Pause" : "Play",
|
|
109
|
+
children: n.playing ? "⏸" : "▶"
|
|
110
|
+
}
|
|
111
|
+
),
|
|
112
|
+
/* @__PURE__ */ c(
|
|
113
|
+
"input",
|
|
114
|
+
{
|
|
115
|
+
type: "range",
|
|
116
|
+
min: 0,
|
|
117
|
+
max: r - 1,
|
|
118
|
+
value: n.frame,
|
|
119
|
+
onChange: o,
|
|
120
|
+
style: ee
|
|
121
|
+
}
|
|
122
|
+
),
|
|
123
|
+
/* @__PURE__ */ L("span", { style: { minWidth: 100, textAlign: "right", fontVariantNumeric: "tabular-nums" }, children: [
|
|
124
|
+
N(n.frame, e),
|
|
125
|
+
" / ",
|
|
126
|
+
N(r - 1, e)
|
|
127
|
+
] })
|
|
128
|
+
] });
|
|
129
|
+
};
|
|
130
|
+
z.displayName = "PlayerControls";
|
|
131
|
+
class te extends O {
|
|
132
|
+
constructor() {
|
|
133
|
+
super(...arguments);
|
|
134
|
+
D(this, "state", { error: null });
|
|
135
|
+
}
|
|
136
|
+
static getDerivedStateFromError(e) {
|
|
137
|
+
return { error: e };
|
|
138
|
+
}
|
|
139
|
+
componentDidCatch(e, o) {
|
|
140
|
+
console.error("Rendiv Player error:", e, o);
|
|
141
|
+
}
|
|
142
|
+
render() {
|
|
143
|
+
if (this.state.error) {
|
|
144
|
+
const e = this.props.fallback;
|
|
145
|
+
return e ? /* @__PURE__ */ c(e, { error: this.state.error }) : /* @__PURE__ */ c(
|
|
146
|
+
"div",
|
|
147
|
+
{
|
|
148
|
+
style: {
|
|
149
|
+
padding: 20,
|
|
150
|
+
color: "#ff4444",
|
|
151
|
+
backgroundColor: "#1a1a1a",
|
|
152
|
+
fontFamily: "monospace",
|
|
153
|
+
fontSize: 14,
|
|
154
|
+
whiteSpace: "pre-wrap",
|
|
155
|
+
overflow: "auto",
|
|
156
|
+
width: "100%",
|
|
157
|
+
height: "100%"
|
|
158
|
+
},
|
|
159
|
+
children: this.state.error.message
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
return this.props.children;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const re = B((n, r) => {
|
|
167
|
+
const {
|
|
168
|
+
component: e,
|
|
169
|
+
durationInFrames: o,
|
|
170
|
+
fps: a,
|
|
171
|
+
compositionWidth: i,
|
|
172
|
+
compositionHeight: p,
|
|
173
|
+
controls: P = !1,
|
|
174
|
+
loop: b = !1,
|
|
175
|
+
autoPlay: g = !1,
|
|
176
|
+
playbackRate: m = 1,
|
|
177
|
+
inputProps: u = {},
|
|
178
|
+
style: k,
|
|
179
|
+
errorFallback: F
|
|
180
|
+
} = n, w = v(null), l = x(() => new Y(), []), [E, f] = M(i), t = X({
|
|
181
|
+
fps: a,
|
|
182
|
+
durationInFrames: o,
|
|
183
|
+
loop: b,
|
|
184
|
+
playbackRate: m,
|
|
185
|
+
autoPlay: g
|
|
186
|
+
});
|
|
187
|
+
R(() => {
|
|
188
|
+
const s = w.current;
|
|
189
|
+
if (!s) return;
|
|
190
|
+
const I = new ResizeObserver(($) => {
|
|
191
|
+
for (const j of $)
|
|
192
|
+
f(j.contentRect.width);
|
|
193
|
+
});
|
|
194
|
+
return I.observe(s), () => I.disconnect();
|
|
195
|
+
}, []), R(() => {
|
|
196
|
+
l.emit("frameupdate", { frame: t.frame });
|
|
197
|
+
}, [t.frame, l]), R(() => {
|
|
198
|
+
t.playing ? l.emit("play") : l.emit("pause");
|
|
199
|
+
}, [t.playing, l]);
|
|
200
|
+
const C = v(t.frame);
|
|
201
|
+
C.current = t.frame;
|
|
202
|
+
const h = v(t.playing);
|
|
203
|
+
h.current = t.playing, G(r, () => ({
|
|
204
|
+
play: t.play,
|
|
205
|
+
pause: t.pause,
|
|
206
|
+
toggle: t.toggle,
|
|
207
|
+
seekTo: t.seekTo,
|
|
208
|
+
getCurrentFrame: () => C.current,
|
|
209
|
+
isPlaying: () => h.current,
|
|
210
|
+
getContainerNode: () => w.current,
|
|
211
|
+
mute: () => {
|
|
212
|
+
},
|
|
213
|
+
unmute: () => {
|
|
214
|
+
},
|
|
215
|
+
setVolume: () => {
|
|
216
|
+
},
|
|
217
|
+
addEventListener: l.addEventListener.bind(l),
|
|
218
|
+
removeEventListener: l.removeEventListener.bind(l)
|
|
219
|
+
}));
|
|
220
|
+
const T = x(
|
|
221
|
+
() => ({
|
|
222
|
+
id: "player",
|
|
223
|
+
width: i,
|
|
224
|
+
height: p,
|
|
225
|
+
fps: a,
|
|
226
|
+
durationInFrames: o,
|
|
227
|
+
defaultProps: u
|
|
228
|
+
}),
|
|
229
|
+
[i, p, a, o, u]
|
|
230
|
+
), d = x(
|
|
231
|
+
() => ({
|
|
232
|
+
frame: t.frame,
|
|
233
|
+
playing: t.playing,
|
|
234
|
+
playingRef: { current: t.playing }
|
|
235
|
+
}),
|
|
236
|
+
[t.frame, t.playing]
|
|
237
|
+
), S = x(
|
|
238
|
+
() => ({ environment: "player" }),
|
|
239
|
+
[]
|
|
240
|
+
), A = E / i, H = p * A, V = y(
|
|
241
|
+
(s) => {
|
|
242
|
+
s.key === " " || s.key === "k" ? (s.preventDefault(), t.toggle()) : s.key === "ArrowLeft" ? (s.preventDefault(), t.seekTo(t.frame - 1)) : s.key === "ArrowRight" ? (s.preventDefault(), t.seekTo(t.frame + 1)) : s.key === "0" && (s.preventDefault(), t.seekTo(0));
|
|
243
|
+
},
|
|
244
|
+
[t]
|
|
245
|
+
), W = /* @__PURE__ */ c(te, { fallback: F, children: /* @__PURE__ */ c(e, { ...u }) });
|
|
246
|
+
return /* @__PURE__ */ L(
|
|
247
|
+
"div",
|
|
248
|
+
{
|
|
249
|
+
ref: w,
|
|
250
|
+
style: {
|
|
251
|
+
position: "relative",
|
|
252
|
+
overflow: "hidden",
|
|
253
|
+
width: "100%",
|
|
254
|
+
height: H,
|
|
255
|
+
backgroundColor: "#000",
|
|
256
|
+
...k
|
|
257
|
+
},
|
|
258
|
+
tabIndex: 0,
|
|
259
|
+
onKeyDown: V,
|
|
260
|
+
children: [
|
|
261
|
+
/* @__PURE__ */ c(
|
|
262
|
+
"div",
|
|
263
|
+
{
|
|
264
|
+
style: {
|
|
265
|
+
width: i,
|
|
266
|
+
height: p,
|
|
267
|
+
transform: `scale(${A})`,
|
|
268
|
+
transformOrigin: "top left",
|
|
269
|
+
overflow: "hidden"
|
|
270
|
+
},
|
|
271
|
+
children: /* @__PURE__ */ c(J.Provider, { value: S, children: /* @__PURE__ */ c(Q.Provider, { value: T, children: /* @__PURE__ */ c(U.Provider, { value: d, children: W }) }) })
|
|
272
|
+
}
|
|
273
|
+
),
|
|
274
|
+
P && /* @__PURE__ */ c(
|
|
275
|
+
z,
|
|
276
|
+
{
|
|
277
|
+
player: t,
|
|
278
|
+
durationInFrames: o,
|
|
279
|
+
fps: a
|
|
280
|
+
}
|
|
281
|
+
)
|
|
282
|
+
]
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
});
|
|
286
|
+
re.displayName = "Player";
|
|
287
|
+
export {
|
|
288
|
+
re as Player
|
|
289
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface UsePlayerOptions {
|
|
2
|
+
fps: number;
|
|
3
|
+
durationInFrames: number;
|
|
4
|
+
loop: boolean;
|
|
5
|
+
playbackRate: number;
|
|
6
|
+
autoPlay: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface UsePlayerReturn {
|
|
9
|
+
frame: number;
|
|
10
|
+
playing: boolean;
|
|
11
|
+
play: () => void;
|
|
12
|
+
pause: () => void;
|
|
13
|
+
toggle: () => void;
|
|
14
|
+
seekTo: (frame: number) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function usePlayer(options: UsePlayerOptions): UsePlayerReturn;
|
|
17
|
+
//# sourceMappingURL=use-player.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-player.d.ts","sourceRoot":"","sources":["../src/use-player.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAyEpE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rendiv/player",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
21
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
22
|
+
"@rendiv/core": "0.1.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/react": "^19.0.0",
|
|
26
|
+
"@types/react-dom": "^19.0.0",
|
|
27
|
+
"react": "^19.0.0",
|
|
28
|
+
"react-dom": "^19.0.0",
|
|
29
|
+
"vite": "^6.0.0",
|
|
30
|
+
"vite-plugin-dts": "^4.3.0",
|
|
31
|
+
"typescript": "^5.7.0",
|
|
32
|
+
"@rendiv/tsconfig": "0.0.0",
|
|
33
|
+
"@rendiv/core": "0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "vite build",
|
|
37
|
+
"dev": "vite build --watch",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"clean": "rm -rf dist"
|
|
40
|
+
}
|
|
41
|
+
}
|