@rendiv/player 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Player.d.ts CHANGED
@@ -9,6 +9,8 @@ export interface PlayerProps {
9
9
  fps: number;
10
10
  compositionWidth: number;
11
11
  compositionHeight: number;
12
+ /** Composition id exposed via CompositionContext. Defaults to 'player'. */
13
+ compositionId?: string;
12
14
  style?: CSSProperties;
13
15
  controls?: boolean;
14
16
  loop?: boolean;
@@ -1 +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,EA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,EAClD,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAClC,IAAI,CAAC;CACX;AAED,eAAO,MAAM,MAAM,+EA4KjB,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +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;
1
+ "use strict";var V=Object.defineProperty;var W=(o,r,e)=>r in o?V(o,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[r]=e;var j=(o,r,e)=>W(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 $(o){const{fps:r,durationInFrames:e,loop:s,playbackRate:i,autoPlay:c}=o,[h,k]=n.useState(0),[x,y]=n.useState(c),m=n.useRef(null),v=n.useRef(0),p=n.useRef(0),w=n.useCallback(()=>y(!0),[]),P=n.useCallback(()=>y(!1),[]),C=n.useCallback(()=>y(f=>!f),[]),u=n.useCallback(f=>{const g=Math.max(0,Math.min(f,e-1));p.current=g,k(g)},[e]);return n.useEffect(()=>{if(!x){m.current=null,v.current=0;return}let f;const g=1e3/(r*i),t=b=>{m.current===null&&(m.current=b);const S=b-m.current;m.current=b,v.current+=S;let d=p.current,R=!1;for(;v.current>=g;)if(v.current-=g,d+=1,R=!0,d>=e)if(s)d=0;else{d=e-1,y(!1);break}R&&(p.current=d,k(d)),f=requestAnimationFrame(t)};return f=requestAnimationFrame(t),()=>cancelAnimationFrame(f)},[x,r,i,s,e]),{frame:h,playing:x,play:w,pause:P,toggle:C,seekTo:u}}class O{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 K={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"},B={background:"none",border:"none",color:"#fff",cursor:"pointer",fontSize:16,padding:"2px 6px",lineHeight:1},G={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:K,children:[a.jsx("button",{type:"button",style:B,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:G}),a.jsxs("span",{style:{minWidth:100,textAlign:"right",fontVariantNumeric:"tabular-nums"},children:[T(o.frame,e)," / ",T(r-1,e)]})]})};D.displayName="PlayerControls";class J 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:h,compositionId:k="player",controls:x=!1,loop:y=!1,autoPlay:m=!1,playbackRate:v=1,inputProps:p={},style:w,errorFallback:P}=o,C=n.useRef(null),u=n.useMemo(()=>new O,[]),[f,g]=n.useState(c),t=$({fps:i,durationInFrames:s,loop:y,playbackRate:v,autoPlay:m});n.useEffect(()=>{const l=C.current;if(!l)return;const M=new ResizeObserver(z=>{for(const H of z)g(H.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 b=n.useRef(t.frame);b.current=t.frame;const S=n.useRef(t.playing);S.current=t.playing,n.useImperativeHandle(r,()=>({play:t.play,pause:t.pause,toggle:t.toggle,seekTo:t.seekTo,getCurrentFrame:()=>b.current,isPlaying:()=>S.current,getContainerNode:()=>C.current,mute:()=>{},unmute:()=>{},setVolume:()=>{},addEventListener:u.addEventListener.bind(u),removeEventListener:u.removeEventListener.bind(u)}));const d=n.useMemo(()=>({id:k,width:c,height:h,fps:i,durationInFrames:s,defaultProps:p}),[k,c,h,i,s,p]),R=n.useMemo(()=>({frame:t.frame,playing:t.playing,playingRef:{current:t.playing}}),[t.frame,t.playing]),A=n.useMemo(()=>({environment:"player"}),[]),F=f/c,I=h*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]),N=a.jsx(J,{fallback:P,children:a.jsx(e,{...p})});return a.jsxs("div",{ref:C,style:{position:"relative",overflow:"hidden",width:"100%",height:I,backgroundColor:"#000",...w},tabIndex:0,onKeyDown:q,children:[a.jsx("div",{style:{width:c,height:h,transform:`scale(${F})`,transformOrigin:"top left",overflow:"hidden"},children:a.jsx(E.RendivEnvironmentContext.Provider,{value:A,children:a.jsx(E.CompositionContext.Provider,{value:d,children:a.jsx(E.TimelineContext.Provider,{value:R,children:N})})})}),x&&a.jsx(D,{player:t,durationInFrames:s,fps:i})]})});L.displayName="Player";exports.Player=L;
package/dist/index.js CHANGED
@@ -1,42 +1,42 @@
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);
1
+ var K = Object.defineProperty;
2
+ var O = (n, r, e) => r in n ? K(n, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[r] = e;
3
+ var D = (n, r, e) => O(n, typeof r != "symbol" ? r + "" : r, e);
4
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(
5
+ import { useState as M, useRef as k, useCallback as b, useEffect as F, Component as B, forwardRef as G, useMemo as R, useImperativeHandle as J } from "react";
6
+ import { RendivEnvironmentContext as Q, CompositionContext as U, TimelineContext as X } from "@rendiv/core";
7
+ function Y(n) {
8
+ const { fps: r, durationInFrames: e, loop: o, playbackRate: a, autoPlay: i } = n, [g, w] = M(0), [C, h] = M(i), d = k(null), y = k(0), m = k(0), E = b(() => h(!0), []), T = b(() => h(!1), []), P = b(() => h((f) => !f), []), l = b(
9
9
  (f) => {
10
- const t = Math.max(0, Math.min(f, e - 1));
11
- k.current = t, P(t);
10
+ const p = Math.max(0, Math.min(f, e - 1));
11
+ m.current = p, w(p);
12
12
  },
13
13
  [e]
14
14
  );
15
- return R(() => {
16
- if (!b) {
17
- m.current = null, u.current = 0;
15
+ return F(() => {
16
+ if (!C) {
17
+ d.current = null, y.current = 0;
18
18
  return;
19
19
  }
20
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)
21
+ const p = 1e3 / (r * a), t = (v) => {
22
+ d.current === null && (d.current = v);
23
+ const S = v - d.current;
24
+ d.current = v, y.current += S;
25
+ let u = m.current, x = !1;
26
+ for (; y.current >= p; )
27
+ if (y.current -= p, u += 1, x = !0, u >= e)
28
28
  if (o)
29
- d = 0;
29
+ u = 0;
30
30
  else {
31
- d = e - 1, g(!1);
31
+ u = e - 1, h(!1);
32
32
  break;
33
33
  }
34
- S && (k.current = d, P(d)), f = requestAnimationFrame(C);
34
+ x && (m.current = u, w(u)), f = requestAnimationFrame(t);
35
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 };
36
+ return f = requestAnimationFrame(t), () => cancelAnimationFrame(f);
37
+ }, [C, r, a, o, e]), { frame: g, playing: C, play: E, pause: T, toggle: P, seekTo: l };
38
38
  }
39
- class Y {
39
+ class Z {
40
40
  constructor() {
41
41
  D(this, "listeners", /* @__PURE__ */ new Map());
42
42
  }
@@ -55,7 +55,7 @@ class Y {
55
55
  i(a);
56
56
  }
57
57
  }
58
- const Z = {
58
+ const _ = {
59
59
  position: "absolute",
60
60
  bottom: 0,
61
61
  left: 0,
@@ -69,7 +69,7 @@ const Z = {
69
69
  fontFamily: "system-ui, -apple-system, sans-serif",
70
70
  fontSize: 13,
71
71
  userSelect: "none"
72
- }, _ = {
72
+ }, ee = {
73
73
  background: "none",
74
74
  border: "none",
75
75
  color: "#fff",
@@ -77,7 +77,7 @@ const Z = {
77
77
  fontSize: 16,
78
78
  padding: "2px 6px",
79
79
  lineHeight: 1
80
- }, ee = {
80
+ }, te = {
81
81
  flex: 1,
82
82
  height: 4,
83
83
  cursor: "pointer",
@@ -92,18 +92,18 @@ const z = ({
92
92
  durationInFrames: r,
93
93
  fps: e
94
94
  }) => {
95
- const o = y(
95
+ const o = b(
96
96
  (a) => {
97
97
  n.seekTo(Number(a.target.value));
98
98
  },
99
99
  [n]
100
100
  );
101
- return /* @__PURE__ */ L("div", { style: Z, children: [
101
+ return /* @__PURE__ */ L("div", { style: _, children: [
102
102
  /* @__PURE__ */ c(
103
103
  "button",
104
104
  {
105
105
  type: "button",
106
- style: _,
106
+ style: ee,
107
107
  onClick: n.toggle,
108
108
  "aria-label": n.playing ? "Pause" : "Play",
109
109
  children: n.playing ? "⏸" : "▶"
@@ -117,7 +117,7 @@ const z = ({
117
117
  max: r - 1,
118
118
  value: n.frame,
119
119
  onChange: o,
120
- style: ee
120
+ style: te
121
121
  }
122
122
  ),
123
123
  /* @__PURE__ */ L("span", { style: { minWidth: 100, textAlign: "right", fontVariantNumeric: "tabular-nums" }, children: [
@@ -128,7 +128,7 @@ const z = ({
128
128
  ] });
129
129
  };
130
130
  z.displayName = "PlayerControls";
131
- class te extends O {
131
+ class re extends B {
132
132
  constructor() {
133
133
  super(...arguments);
134
134
  D(this, "state", { error: null });
@@ -163,51 +163,52 @@ class te extends O {
163
163
  return this.props.children;
164
164
  }
165
165
  }
166
- const re = B((n, r) => {
166
+ const ne = G((n, r) => {
167
167
  const {
168
168
  component: e,
169
169
  durationInFrames: o,
170
170
  fps: a,
171
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({
172
+ compositionHeight: g,
173
+ compositionId: w = "player",
174
+ controls: C = !1,
175
+ loop: h = !1,
176
+ autoPlay: d = !1,
177
+ playbackRate: y = 1,
178
+ inputProps: m = {},
179
+ style: E,
180
+ errorFallback: T
181
+ } = n, P = k(null), l = R(() => new Z(), []), [f, p] = M(i), t = Y({
181
182
  fps: a,
182
183
  durationInFrames: o,
183
- loop: b,
184
- playbackRate: m,
185
- autoPlay: g
184
+ loop: h,
185
+ playbackRate: y,
186
+ autoPlay: d
186
187
  });
187
- R(() => {
188
- const s = w.current;
188
+ F(() => {
189
+ const s = P.current;
189
190
  if (!s) return;
190
- const I = new ResizeObserver(($) => {
191
- for (const j of $)
192
- f(j.contentRect.width);
191
+ const I = new ResizeObserver((j) => {
192
+ for (const q of j)
193
+ p(q.contentRect.width);
193
194
  });
194
195
  return I.observe(s), () => I.disconnect();
195
- }, []), R(() => {
196
+ }, []), F(() => {
196
197
  l.emit("frameupdate", { frame: t.frame });
197
- }, [t.frame, l]), R(() => {
198
+ }, [t.frame, l]), F(() => {
198
199
  t.playing ? l.emit("play") : l.emit("pause");
199
200
  }, [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, () => ({
201
+ const v = k(t.frame);
202
+ v.current = t.frame;
203
+ const S = k(t.playing);
204
+ S.current = t.playing, J(r, () => ({
204
205
  play: t.play,
205
206
  pause: t.pause,
206
207
  toggle: t.toggle,
207
208
  seekTo: t.seekTo,
208
- getCurrentFrame: () => C.current,
209
- isPlaying: () => h.current,
210
- getContainerNode: () => w.current,
209
+ getCurrentFrame: () => v.current,
210
+ isPlaying: () => S.current,
211
+ getContainerNode: () => P.current,
211
212
  mute: () => {
212
213
  },
213
214
  unmute: () => {
@@ -217,61 +218,61 @@ const re = B((n, r) => {
217
218
  addEventListener: l.addEventListener.bind(l),
218
219
  removeEventListener: l.removeEventListener.bind(l)
219
220
  }));
220
- const T = x(
221
+ const u = R(
221
222
  () => ({
222
- id: "player",
223
+ id: w,
223
224
  width: i,
224
- height: p,
225
+ height: g,
225
226
  fps: a,
226
227
  durationInFrames: o,
227
- defaultProps: u
228
+ defaultProps: m
228
229
  }),
229
- [i, p, a, o, u]
230
- ), d = x(
230
+ [w, i, g, a, o, m]
231
+ ), x = R(
231
232
  () => ({
232
233
  frame: t.frame,
233
234
  playing: t.playing,
234
235
  playingRef: { current: t.playing }
235
236
  }),
236
237
  [t.frame, t.playing]
237
- ), S = x(
238
+ ), H = R(
238
239
  () => ({ environment: "player" }),
239
240
  []
240
- ), A = E / i, H = p * A, V = y(
241
+ ), A = f / i, V = g * A, W = b(
241
242
  (s) => {
242
243
  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
  },
244
245
  [t]
245
- ), W = /* @__PURE__ */ c(te, { fallback: F, children: /* @__PURE__ */ c(e, { ...u }) });
246
+ ), $ = /* @__PURE__ */ c(re, { fallback: T, children: /* @__PURE__ */ c(e, { ...m }) });
246
247
  return /* @__PURE__ */ L(
247
248
  "div",
248
249
  {
249
- ref: w,
250
+ ref: P,
250
251
  style: {
251
252
  position: "relative",
252
253
  overflow: "hidden",
253
254
  width: "100%",
254
- height: H,
255
+ height: V,
255
256
  backgroundColor: "#000",
256
- ...k
257
+ ...E
257
258
  },
258
259
  tabIndex: 0,
259
- onKeyDown: V,
260
+ onKeyDown: W,
260
261
  children: [
261
262
  /* @__PURE__ */ c(
262
263
  "div",
263
264
  {
264
265
  style: {
265
266
  width: i,
266
- height: p,
267
+ height: g,
267
268
  transform: `scale(${A})`,
268
269
  transformOrigin: "top left",
269
270
  overflow: "hidden"
270
271
  },
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
+ children: /* @__PURE__ */ c(Q.Provider, { value: H, children: /* @__PURE__ */ c(U.Provider, { value: u, children: /* @__PURE__ */ c(X.Provider, { value: x, children: $ }) }) })
272
273
  }
273
274
  ),
274
- P && /* @__PURE__ */ c(
275
+ C && /* @__PURE__ */ c(
275
276
  z,
276
277
  {
277
278
  player: t,
@@ -283,7 +284,7 @@ const re = B((n, r) => {
283
284
  }
284
285
  );
285
286
  });
286
- re.displayName = "Player";
287
+ ne.displayName = "Player";
287
288
  export {
288
- re as Player
289
+ ne as Player
289
290
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rendiv/player",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -19,7 +19,7 @@
19
19
  "peerDependencies": {
20
20
  "react": "^18.0.0 || ^19.0.0",
21
21
  "react-dom": "^18.0.0 || ^19.0.0",
22
- "@rendiv/core": "0.1.2"
22
+ "@rendiv/core": "0.1.4"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/react": "^19.0.0",
@@ -30,7 +30,7 @@
30
30
  "vite-plugin-dts": "^4.3.0",
31
31
  "typescript": "^5.7.0",
32
32
  "@rendiv/tsconfig": "0.0.0",
33
- "@rendiv/core": "0.1.2"
33
+ "@rendiv/core": "0.1.4"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "vite build",