@aigamo/nostalgic-diva
Advanced tools
Comparing version 1.8.0 to 1.9.1
import React from 'react'; | ||
import { PlayerOptions, PlayerType } from '../players/PlayerApi'; | ||
interface NostalgicDivaProps { | ||
type: PlayerType; | ||
export interface NostalgicDivaProps { | ||
type: `${PlayerType}`; | ||
videoId: string; | ||
@@ -9,2 +9,1 @@ options?: PlayerOptions; | ||
export declare const NostalgicDiva: React.MemoExoticComponent<({ type, videoId, options }: NostalgicDivaProps) => React.ReactElement>; | ||
export {}; |
@@ -7,3 +7,3 @@ import React from 'react'; | ||
logger: ILogger; | ||
type: PlayerType; | ||
type: `${PlayerType}`; | ||
playerApiRef: React.MutableRefObject<IPlayerApi | undefined> | undefined; | ||
@@ -10,0 +10,0 @@ videoId: string; |
@@ -1,2 +0,2 @@ | ||
"use strict";var O=Object.defineProperty;var W=(a,t,e)=>t in a?O(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var g=(a,t,e)=>(W(a,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react");var u=(a=>(a[a.Trace=0]="Trace",a[a.Debug=1]="Debug",a[a.Information=2]="Information",a[a.Warning=3]="Warning",a[a.Error=4]="Error",a[a.Critical=5]="Critical",a[a.None=6]="None",a))(u||{});class w{constructor(t,e,r){this.logger=t,this.player=e,this.options=r,this.logger.log(u.Debug,"ctor")}}class N extends w{async attach(){this.player.onerror=t=>{var e,r;return(r=(e=this.options)==null?void 0:e.onError)==null?void 0:r.call(e,t)},this.player.onloadeddata=()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onLoaded)==null?void 0:e.call(t,{id:this.player.src})},this.player.onplay=()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onPlay)==null?void 0:e.call(t)},this.player.onpause=()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onPause)==null?void 0:e.call(t)},this.player.onended=()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onEnded)==null?void 0:e.call(t)},this.player.ontimeupdate=()=>{var t,e;(e=(t=this.options)==null?void 0:t.onTimeUpdate)==null||e.call(t,{duration:this.player.duration,percent:this.player.currentTime/this.player.duration,seconds:this.player.currentTime})}}async detach(){this.player.onerror=null,this.player.onloadeddata=null,this.player.onplay=null,this.player.onpause=null,this.player.onended=null,this.player.ontimeupdate=null}async loadVideo(t){this.player.src=t}async play(){this.player.play()}async pause(){this.player.pause()}async setCurrentTime(t){this.player.currentTime=t}async setVolume(t){this.player.volume=t}async setMuted(t){this.player.muted=t}async setPlaybackRate(t){this.player.playbackRate=t}async getDuration(){return this.player.duration}async getCurrentTime(){return this.player.currentTime}async getVolume(){return this.player.volume}async getPlaybackRate(){return this.player.playbackRate}}const R=class{constructor(t,e,r,i,l){g(this,"id");g(this,"impl");this.logger=t,this.type=e,this.player=r,this.options=i,this.playerApiFactory=l,this.id=R.nextId++}createMessage(t){return`${this.type}#${this.id} ${t}`}debug(t,...e){this.logger.log(u.Debug,this.createMessage(t),...e)}error(t,...e){this.logger.log(u.Error,this.createMessage(t),...e)}async attach(t){if(this.debug("attach",t),this.impl){this.debug("player is already attached");return}this.debug("Attaching player..."),this.impl=new this.playerApiFactory(this.logger,this.player,this.options),await this.impl.attach(t),this.debug("player attached")}createPlayerNotAttachedError(){return new Error("player is not attached")}async detach(){if(this.debug("detach"),this.impl===void 0)throw this.createPlayerNotAttachedError();await this.impl.detach(),this.impl=void 0}async loadVideo(t){if(this.debug("loadVideo",t),this.impl===void 0)throw this.createPlayerNotAttachedError();this.debug("Loading video..."),await this.impl.loadVideo(t),this.debug("video loaded",t)}play(){if(this.debug("play"),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.play()}pause(){if(this.debug("pause"),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.pause()}setCurrentTime(t){if(this.debug("setCurrentTime",t),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.setCurrentTime(t)}setVolume(t){if(this.debug("setVolume",t),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.setVolume(t)}setMuted(t){if(this.debug("setMuted",t),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.setMuted(t)}setPlaybackRate(t){if(this.debug("setPlaybackRate",t),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.setPlaybackRate(t)}getDuration(){if(this.debug("getDuration"),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.getDuration()}getCurrentTime(){if(this.debug("getCurrentTime"),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.getCurrentTime()}getVolume(){if(this.debug("getVolume"),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.getVolume()}getPlaybackRate(){if(this.debug("getPlaybackRate"),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.getPlaybackRate()}};let f=R;g(f,"nextId",1);function z(){const a=s.useRef(!0);return a.current?(a.current=!1,!0):a.current}const x=(a,t)=>a===t;function L(a,t=x){const e=s.useRef(),r=s.useRef(a);return!z()&&!t(r.current,a)&&(e.current=r.current,r.current=a),e.current}const E=({logger:a,type:t,loadScript:e,playerFactory:r,playerApiRef:i,videoId:l,options:o,playerApiFactory:n,children:d})=>{a.log(u.Debug,"PlayerContainer");const h=s.useRef(l),p=s.useRef(void 0),[b,P]=s.useState(),[m,v]=s.useState();s.useEffect(()=>{((e==null?void 0:e())??Promise.resolve()).then(()=>{r(p.current,h.current).then(y=>{P(y)})})},[e,r]),s.useEffect(()=>{if(b===void 0)return;const y=new f(a,t,b,o,n);return i&&(i.current=y),y.attach(h.current).then(()=>v(y)),()=>{if(i&&y!==i.current)throw new Error("playerApi differs");y.detach().finally(()=>v(void 0))}},[a,t,e,b,o,n,i]);const c=L(l);return s.useEffect(()=>{c!==void 0&&(m==null||m.loadVideo(l))},[c,l,m]),s.createElement(s.Fragment,null,d(p,h.current))},G=s.memo(({...a})=>{const{logger:t}=a;t.log(u.Debug,"AudioPlayer");const e=s.useCallback(r=>Promise.resolve(r),[]);return s.createElement(E,{...a,loadScript:void 0,playerFactory:e,playerApiFactory:N},(r,i)=>s.createElement("audio",{ref:r,src:i,style:{width:"100%",height:"100%"},preload:"auto",autoPlay:!0,controls:!0}))}),B=Object.freeze(Object.defineProperty({__proto__:null,default:G},Symbol.toStringTag,{value:"Module"})),I=["apiready","seeked","video_end","durationchange","pause","playing","error"];class M extends w{constructor(){super(...arguments);g(this,"handlePlayerEvents",e=>{var r,i,l,o,n,d,h,p,b,P,m,v;switch(e.type){case"apiready":(i=(r=this.options)==null?void 0:r.onLoaded)==null||i.call(r,{id:this.player.video.videoId});break;case"seeked":(o=(l=this.options)==null?void 0:l.onTimeUpdate)==null||o.call(l,{duration:this.player.duration,percent:this.player.currentTime/this.player.duration,seconds:this.player.currentTime});break;case"video_end":(d=(n=this.options)==null?void 0:n.onEnded)==null||d.call(n);break;case"durationchange":break;case"pause":(p=(h=this.options)==null?void 0:h.onPause)==null||p.call(h);break;case"playing":(P=(b=this.options)==null?void 0:b.onPlay)==null||P.call(b);break;case"error":(v=(m=this.options)==null?void 0:m.onError)==null||v.call(m,e);break}})}async attach(e){for(const r of I)this.player.addEventListener(r,this.handlePlayerEvents)}async detach(){for(const e of I)this.player.removeEventListener(e,this.handlePlayerEvents)}async loadVideo(e){this.player.load(e)}async play(){this.player.play()}async pause(){this.player.pause()}async setCurrentTime(e){this.player.seek(e)}async setVolume(e){this.player.setVolume(e)}async setMuted(e){this.player.setMuted(e)}async setPlaybackRate(e){}async getDuration(){return this.player.duration}async getCurrentTime(){return this.player.currentTime}async getVolume(){return this.player.volume}async getPlaybackRate(){return 1}}function q(a){return new Promise((t,e)=>{const r=document.createElement("script");r.src=a,r.async=!0,r.onerror=e,r.onload=r.onreadystatechange=function(){const i=this.readyState;i&&i!=="loaded"&&i!=="complete"||(r.onload=r.onreadystatechange=null,t())},document.head.appendChild(r)})}const V=[];async function k(a,t){if(V.includes(a))return t.log(u.Debug,a,"script is already loaded"),!1;try{return t.log(u.Debug,a,"Loading script..."),await q(a),V.includes(a)?(t.log(u.Debug,a,"script is already loaded"),!1):(V.push(a),t.log(u.Debug,a,"script loaded"),!0)}catch(e){throw t.log(u.Error,a,"Failed to load script"),e}}const H=s.memo(({options:a,...t})=>{const{logger:e}=t;e.log(u.Debug,"DailymotionPlayer");const r=s.useCallback(async()=>{await k("https://api.dmcdn.net/all.js",e)},[e]),i=s.useCallback((l,o)=>Promise.resolve(new DM.player(l,{video:o,width:"100%",height:"100%",events:{apiready:()=>{var n;(n=a==null?void 0:a.onLoaded)==null||n.call(a,{id:o})},seeked:()=>{var n;(n=a==null?void 0:a.onTimeUpdate)==null||n.call(a,{duration:0,percent:0,seconds:0})},video_end:()=>{var n;(n=a==null?void 0:a.onEnded)==null||n.call(a)},durationchange:()=>{},pause:()=>{var n;(n=a==null?void 0:a.onPause)==null||n.call(a)},playing:()=>{var n;(n=a==null?void 0:a.onPlay)==null||n.call(a)},waiting:()=>{},error:n=>{var d;(d=a==null?void 0:a.onError)==null||d.call(a,n)}}})),[a]);return s.createElement(E,{...t,options:a,loadScript:r,playerFactory:i,playerApiFactory:M},l=>s.createElement("div",{style:{width:"100%",height:"100%"}},s.createElement("div",{ref:l})))}),K=Object.freeze(Object.defineProperty({__proto__:null,default:H},Symbol.toStringTag,{value:"Module"}));var A=(a=>(a[a.Play=2]="Play",a[a.Pause=3]="Pause",a[a.End=4]="End",a))(A||{});const C=class extends w{constructor(){super(...arguments);g(this,"duration");g(this,"currentTime");g(this,"volume");g(this,"handleMessage",e=>{var i,l,o,n,d,h,p,b,P,m,v,c,y,S;if(e.origin!==C.origin)return;const r=e.data;switch(r.eventName){case"playerStatusChange":this.logger.log(u.Debug,`player status changed: ${A[r.data.playerStatus]??r.data.playerStatus}`);break;case"statusChange":switch(this.logger.log(u.Debug,`status changed: ${A[r.data.playerStatus]??r.data.playerStatus}`),r.data.playerStatus){case 2:(l=(i=this.options)==null?void 0:i.onPlay)==null||l.call(i);break;case 3:(n=(o=this.options)==null?void 0:o.onPause)==null||n.call(o);break;case 4:(h=(d=this.options)==null?void 0:d.onEnded)==null||h.call(d);break}break;case"playerMetadataChange":r.data.duration!==void 0&&(this.duration=r.data.duration/1e3),this.currentTime=r.data.currentTime===void 0?void 0:r.data.currentTime/1e3,this.volume=r.data.volume,(b=(p=this.options)==null?void 0:p.onTimeUpdate)==null||b.call(p,{duration:this.duration,percent:this.currentTime!==void 0&&this.duration!==void 0?this.currentTime/this.duration:void 0,seconds:this.currentTime});break;case"loadComplete":this.logger.log(u.Debug,"load completed"),this.duration=r.data.videoInfo.lengthInSeconds,(m=(P=this.options)==null?void 0:P.onLoaded)==null||m.call(P,{id:r.data.videoInfo.watchId});break;case"error":(c=(v=this.options)==null?void 0:v.onError)==null||c.call(v,r);break;case"player-error:video:play":case"player-error:video:seek":(S=(y=this.options)==null?void 0:y.onError)==null||S.call(y,r);break;default:this.logger.log(u.Debug,"message",r.eventName,r.data);break}})}async attach(){window.addEventListener("message",this.handleMessage)}async detach(){window.removeEventListener("message",this.handleMessage)}async loadVideo(e){return new Promise((r,i)=>{this.duration=void 0,this.currentTime=void 0,this.player.onload=()=>{this.player.onload=null,r()},this.player.src=`https://embed.nicovideo.jp/watch/${e}?jsapi=1&playerId=1`})}postMessage(e){var r;(r=this.player.contentWindow)==null||r.postMessage({...e,playerId:"1",sourceConnectorType:1},C.origin)}async play(){this.postMessage({eventName:"play"})}async pause(){this.postMessage({eventName:"pause"})}async setCurrentTime(e){this.postMessage({eventName:"seek",data:{time:e*1e3}})}async setVolume(e){this.postMessage({eventName:"volumeChange",data:{volume:e}})}async setMuted(e){this.postMessage({eventName:"mute",data:{mute:e}})}async setPlaybackRate(e){}async getDuration(){return this.duration}async getCurrentTime(){return this.currentTime}async getVolume(){return this.volume}async getPlaybackRate(){return 1}};let T=C;g(T,"origin","https://embed.nicovideo.jp");const J=s.memo(({...a})=>{const{logger:t}=a;t.log(u.Debug,"NiconicoPlayer");const e=s.useCallback(r=>Promise.resolve(r),[]);return s.createElement(E,{...a,loadScript:void 0,playerFactory:e,playerApiFactory:T},(r,i)=>s.createElement("div",{style:{width:"100%",height:"100%"}},s.createElement("iframe",{ref:r,src:`https://embed.nicovideo.jp/watch/${i}?jsapi=1&playerId=1`,width:"100%",height:"100%",allowFullScreen:!0,style:{border:"none"},allow:"autoplay; fullscreen"})))}),Q=Object.freeze(Object.defineProperty({__proto__:null,default:J},Symbol.toStringTag,{value:"Module"})),U=s.createContext(void 0),X=new class{constructor(){g(this,"title","nostalgic-diva")}createMessage(a){return`[${this.title}] ${a}`}debug(a,...t){console.debug(this.createMessage(a),...t)}error(a,...t){console.error(this.createMessage(a),...t)}warn(a,...t){console.warn(this.createMessage(a),...t)}isEnabled(){return!0}log(a,t,...e){switch(a){case u.Debug:this.debug(t,...e);break;case u.Warning:this.warn(t,...e);break;case u.Error:this.error(t,...e);break}}},Z=({logger:a=X,children:t})=>{const e=s.useRef(),r=s.useCallback(async c=>{var y;await((y=e.current)==null?void 0:y.loadVideo(c))},[]),i=s.useCallback(async()=>{var c;await((c=e.current)==null?void 0:c.play())},[]),l=s.useCallback(async()=>{var c;await((c=e.current)==null?void 0:c.pause())},[]),o=s.useCallback(async c=>{const y=e.current;y&&(await y.setCurrentTime(c),await y.play())},[]),n=s.useCallback(async c=>{var y;await((y=e.current)==null?void 0:y.setVolume(c))},[]),d=s.useCallback(async c=>{var y;await((y=e.current)==null?void 0:y.setMuted(c))},[]),h=s.useCallback(async c=>{var y;await((y=e.current)==null?void 0:y.setPlaybackRate(c))},[]),p=s.useCallback(async()=>{var c;return await((c=e.current)==null?void 0:c.getDuration())},[]),b=s.useCallback(async()=>{var c;return await((c=e.current)==null?void 0:c.getCurrentTime())},[]),P=s.useCallback(async()=>{var c;return await((c=e.current)==null?void 0:c.getVolume())},[]),m=s.useCallback(async()=>{var c;return await((c=e.current)==null?void 0:c.getPlaybackRate())},[]),v=s.useMemo(()=>({logger:a,playerApiRef:e,loadVideo:r,play:i,pause:l,setCurrentTime:o,setVolume:n,setMuted:d,setPlaybackRate:h,getDuration:p,getCurrentTime:b,getVolume:P,getPlaybackRate:m}),[a,r,i,l,o,n,d,h,p,b,P,m]);return s.createElement(U.Provider,{value:v},t)},j=()=>s.useContext(U),ee=s.lazy(()=>Promise.resolve().then(()=>B)),te=s.lazy(()=>Promise.resolve().then(()=>K)),ae=s.lazy(()=>Promise.resolve().then(()=>Q)),re=s.lazy(()=>Promise.resolve().then(()=>ue)),se=s.lazy(()=>Promise.resolve().then(()=>ye)),ie=s.lazy(()=>Promise.resolve().then(()=>be)),ne=s.lazy(()=>Promise.resolve().then(()=>me)),oe={Audio:ee,Dailymotion:te,Niconico:ae,SoundCloud:re,Twitch:se,Vimeo:ie,YouTube:ne},le=s.memo(({type:a,videoId:t,options:e})=>{const{logger:r,playerApiRef:i}=j();r.log(u.Debug,"NostalgicDiva");const l=oe[a];return s.createElement(s.Suspense,{fallback:null},s.createElement(l,{logger:r,type:a,playerApiRef:i,videoId:t,options:e}))});class D extends w{getDurationCore(){return new Promise((t,e)=>{this.player.getDuration(t)})}attach(t){return new Promise((e,r)=>{this.player.bind(SC.Widget.Events.READY,()=>{var i,l;this.player.bind(SC.Widget.Events.PLAY_PROGRESS,async o=>{var d,h;const n=await this.getDurationCore();(h=(d=this.options)==null?void 0:d.onTimeUpdate)==null||h.call(d,{duration:n/1e3,percent:o.currentPosition/n,seconds:o.currentPosition/1e3})}),this.player.bind(SC.Widget.Events.ERROR,o=>{var n,d;return(d=(n=this.options)==null?void 0:n.onError)==null?void 0:d.call(n,o)}),this.player.bind(SC.Widget.Events.PLAY,()=>{var o,n;return(n=(o=this.options)==null?void 0:o.onPlay)==null?void 0:n.call(o)}),this.player.bind(SC.Widget.Events.PAUSE,()=>{var o,n;return(n=(o=this.options)==null?void 0:o.onPause)==null?void 0:n.call(o)}),this.player.bind(SC.Widget.Events.FINISH,()=>{var o,n;return(n=(o=this.options)==null?void 0:o.onEnded)==null?void 0:n.call(o)}),(l=(i=this.options)==null?void 0:i.onLoaded)==null||l.call(i,{id:t}),e()})})}async detach(){this.player.unbind(SC.Widget.Events.READY),this.player.unbind(SC.Widget.Events.PLAY_PROGRESS),this.player.unbind(SC.Widget.Events.ERROR),this.player.unbind(SC.Widget.Events.PLAY),this.player.unbind(SC.Widget.Events.PAUSE),this.player.unbind(SC.Widget.Events.FINISH)}static playerLoadAsync(t,e,r){return new Promise((i,l)=>{t.load(e,{...r,callback:i})})}async loadVideo(t){var e,r;await D.playerLoadAsync(this.player,t,{auto_play:!0}),(r=(e=this.options)==null?void 0:e.onLoaded)==null||r.call(e,{id:t})}async play(){this.player.play()}async pause(){this.player.pause()}async setCurrentTime(t){this.player.seekTo(t*1e3)}async setVolume(t){this.player.setVolume(t*100)}async setMuted(t){this.setVolume(t?0:1)}async setPlaybackRate(t){}async getDuration(){return await this.getDurationCore()/1e3}getCurrentTimeCore(){return new Promise((t,e)=>{this.player.getPosition(t)})}async getCurrentTime(){return await this.getCurrentTimeCore()/1e3}getVolumeCore(){return new Promise((t,e)=>{this.player.getVolume(t)})}async getVolume(){return await this.getVolumeCore()/100}async getPlaybackRate(){return 1}}const ce=s.memo(({...a})=>{const{logger:t}=a;t.log(u.Debug,"SoundCloudPlayer");const e=s.useCallback(async()=>{await k("https://w.soundcloud.com/player/api.js",t)},[t]),r=s.useCallback(i=>Promise.resolve(SC.Widget(i)),[]);return s.createElement(E,{...a,loadScript:e,playerFactory:r,playerApiFactory:D},(i,l)=>s.createElement("iframe",{ref:i,src:`https://w.soundcloud.com/player/?url=${l}`,frameBorder:0,allow:"autoplay",style:{width:"100%",height:"100%"}}))}),ue=Object.freeze(Object.defineProperty({__proto__:null,default:ce},Symbol.toStringTag,{value:"Module"}));class _ extends w{constructor(){super(...arguments);g(this,"handleReady",()=>{var e,r;(r=(e=this.options)==null?void 0:e.onLoaded)==null||r.call(e,{id:this.player.getVideo()})});g(this,"handlePlay",()=>{var e,r;(r=(e=this.options)==null?void 0:e.onPlay)==null||r.call(e)});g(this,"handlePause",()=>{var e,r;(r=(e=this.options)==null?void 0:e.onPause)==null||r.call(e)});g(this,"handleEnded",()=>{var e,r;(r=(e=this.options)==null?void 0:e.onEnded)==null||r.call(e)});g(this,"handleSeek",()=>{var e,r;(r=(e=this.options)==null?void 0:e.onTimeUpdate)==null||r.call(e,{duration:0,percent:0,seconds:0})})}async attach(e){this.player.addEventListener(Twitch.Player.READY,this.handleReady),this.player.addEventListener(Twitch.Player.PLAYING,this.handlePlay),this.player.addEventListener(Twitch.Player.PAUSE,this.handlePause),this.player.addEventListener(Twitch.Player.ENDED,this.handleEnded),this.player.addEventListener(Twitch.Player.SEEK,this.handleSeek)}async detach(){}async loadVideo(e){this.player.setVideo(e,0)}async play(){this.player.play()}async pause(){this.player.pause()}async setCurrentTime(e){this.player.seek(e)}async setVolume(e){this.player.setVolume(e)}async setMuted(e){this.player.setMuted(e)}async setPlaybackRate(e){}async getDuration(){return this.player.getDuration()}async getCurrentTime(){return this.player.getCurrentTime()}async getVolume(){return this.player.getVolume()}async getPlaybackRate(){return 1}}const de=s.memo(({...a})=>{const{logger:t}=a;t.log(u.Debug,"TwitchPlayer");const e=s.useCallback(async()=>{await k("https://embed.twitch.tv/embed/v1.js",t)},[t]),r=s.useCallback(async(i,l)=>Promise.resolve(new Twitch.Player(i,{video:l,width:"100%",height:"100%"})),[]);return s.createElement(E,{...a,loadScript:e,playerFactory:r,playerApiFactory:_},i=>s.createElement("div",{ref:i,style:{width:"100%",height:"100%"}}))}),ye=Object.freeze(Object.defineProperty({__proto__:null,default:de},Symbol.toStringTag,{value:"Module"}));var F=(a=>(a[a.UNSTARTED=-1]="UNSTARTED",a[a.ENDED=0]="ENDED",a[a.PLAYING=1]="PLAYING",a[a.PAUSED=2]="PAUSED",a[a.BUFFERING=3]="BUFFERING",a[a.CUED=5]="CUED",a))(F||{});class $ extends w{constructor(){super(...arguments);g(this,"previousTime");g(this,"timeUpdateIntervalId")}clearTimeUpdateInterval(){this.logger.log(u.Debug,"clearTimeUpdateInterval",this.timeUpdateIntervalId),window.clearInterval(this.timeUpdateIntervalId),this.timeUpdateIntervalId=void 0}invokeTimeUpdate(e){var l,o;const r=e.getCurrentTime();if(r===this.previousTime)return;const i=e.getDuration();(o=(l=this.options)==null?void 0:l.onTimeUpdate)==null||o.call(l,{duration:i,percent:r/i,seconds:r}),this.previousTime=r}setTimeUpdateInterval(){this.logger.log(u.Debug,"setTimeUpdateInterval"),this.clearTimeUpdateInterval(),this.timeUpdateIntervalId=window.setInterval(()=>this.invokeTimeUpdate(this.player),250),this.logger.log(u.Debug,"timeUpdateIntervalId",this.timeUpdateIntervalId),this.invokeTimeUpdate(this.player)}attach(e){return new Promise((r,i)=>{this.player.addEventListener("onReady",async()=>{this.player.addEventListener("onError",l=>{var o,n;return(n=(o=this.options)==null?void 0:o.onError)==null?void 0:n.call(o,l.data)}),this.player.addEventListener("onStateChange",l=>{var o,n,d,h,p,b,P,m;switch(this.logger.log(u.Debug,`state changed: ${F[l.data]}`),l.data){case YT.PlayerState.CUED:(n=(o=this.options)==null?void 0:o.onLoaded)==null||n.call(o,{id:e});break;case YT.PlayerState.PLAYING:(h=(d=this.options)==null?void 0:d.onPlay)==null||h.call(d),this.setTimeUpdateInterval();break;case YT.PlayerState.PAUSED:(b=(p=this.options)==null?void 0:p.onPause)==null||b.call(p),this.clearTimeUpdateInterval();break;case YT.PlayerState.ENDED:(m=(P=this.options)==null?void 0:P.onEnded)==null||m.call(P),this.clearTimeUpdateInterval();break}}),await this.loadVideo(e),r()})})}async detach(){this.clearTimeUpdateInterval()}async loadVideo(e){this.previousTime=void 0,this.player.cueVideoById(e)}async play(){this.player.playVideo()}async pause(){this.player.pauseVideo()}async setCurrentTime(e){this.player.seekTo(e),this.invokeTimeUpdate(this.player)}async setVolume(e){this.player.setVolume(e*100)}async setMuted(e){e?this.player.mute():this.player.unMute()}async setPlaybackRate(e){this.player.setPlaybackRate(e)}async getDuration(){return this.player.getDuration()}async getCurrentTime(){return this.player.getCurrentTime()}async getVolume(){return this.player.getVolume()/100}async getPlaybackRate(){return this.player.getPlaybackRate()}}const he="https://www.youtube-nocookie.com",pe=s.memo(({...a})=>{const{logger:t}=a;t.log(u.Debug,"YouTubePlayer");const e=s.useCallback(()=>new Promise(async(i,l)=>{await k("https://www.youtube.com/iframe_api",t)?window.onYouTubeIframeAPIReady=()=>{t.log(u.Debug,"YouTube iframe API ready"),i()}:i()}),[t]),r=s.useCallback(i=>Promise.resolve(new YT.Player(i,{host:he,width:"100%",height:"100%"})),[]);return s.createElement(E,{...a,loadScript:e,playerFactory:r,playerApiFactory:$},i=>s.createElement("div",{style:{width:"100%",height:"100%"}},s.createElement("div",{ref:i})))}),me=Object.freeze(Object.defineProperty({__proto__:null,default:pe},Symbol.toStringTag,{value:"Module"}));class Y extends w{async attach(){await this.player.ready(),this.player.on("error",t=>{var e,r;return(r=(e=this.options)==null?void 0:e.onError)==null?void 0:r.call(e,t)}),this.player.on("loaded",t=>{var e,r;return(r=(e=this.options)==null?void 0:e.onLoaded)==null?void 0:r.call(e,{id:t.id.toString()})}),this.player.on("play",()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onPlay)==null?void 0:e.call(t)}),this.player.on("pause",()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onPause)==null?void 0:e.call(t)}),this.player.on("ended",()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onEnded)==null?void 0:e.call(t)}),this.player.on("timeupdate",t=>{var e,r;(r=(e=this.options)==null?void 0:e.onTimeUpdate)==null||r.call(e,{duration:t.duration,percent:t.percent,seconds:t.seconds})})}async detach(){this.player.off("error"),this.player.off("loaded"),this.player.off("play"),this.player.off("pause"),this.player.off("ended"),this.player.off("timeupdate")}async loadVideo(t){await this.player.loadVideo(t)}async play(){await this.player.play()}async pause(){await this.player.pause()}async setCurrentTime(t){await this.player.setCurrentTime(t)}async setVolume(t){await this.player.setVolume(t)}async setMuted(t){await this.player.setMuted(t)}async setPlaybackRate(t){await this.player.setPlaybackRate(t)}async getDuration(){return this.player.getDuration()}async getCurrentTime(){return this.player.getCurrentTime()}async getVolume(){return this.player.getVolume()}async getPlaybackRate(){return this.player.getPlaybackRate()}}const ge=s.memo(({...a})=>{const{logger:t}=a;t.log(u.Debug,"VimeoPlayer");const e=s.useCallback(async()=>{await k("https://player.vimeo.com/api/player.js",t)},[t]),r=s.useCallback(i=>Promise.resolve(new Vimeo.Player(i)),[]);return s.createElement(E,{...a,loadScript:e,playerFactory:r,playerApiFactory:Y},(i,l)=>s.createElement("iframe",{ref:i,src:`https://player.vimeo.com/video/${l}`,frameBorder:0,allow:"autoplay",style:{width:"100%",height:"100%"}}))}),be=Object.freeze(Object.defineProperty({__proto__:null,default:ge},Symbol.toStringTag,{value:"Module"}));exports.AudioPlayerApi=N;exports.DailymotionPlayerApi=M;exports.NiconicoPlayerApi=T;exports.NostalgicDiva=le;exports.NostalgicDivaProvider=Z;exports.PlayerApi=f;exports.SoundCloudPlayerApi=D;exports.TwitchPlayerApi=_;exports.VimeoPlayerApi=Y;exports.YouTubePlayerApi=$;exports.useNostalgicDiva=j; | ||
"use strict";var W=Object.defineProperty;var z=(a,t,e)=>t in a?W(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var g=(a,t,e)=>(z(a,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react");var u=(a=>(a[a.Trace=0]="Trace",a[a.Debug=1]="Debug",a[a.Information=2]="Information",a[a.Warning=3]="Warning",a[a.Error=4]="Error",a[a.Critical=5]="Critical",a[a.None=6]="None",a))(u||{});class w{constructor(t,e,r){this.logger=t,this.player=e,this.options=r,this.logger.log(u.Debug,"ctor")}}class M extends w{async attach(){this.player.onerror=t=>{var e,r;return(r=(e=this.options)==null?void 0:e.onError)==null?void 0:r.call(e,t)},this.player.onloadeddata=()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onLoaded)==null?void 0:e.call(t,{id:this.player.src})},this.player.onplay=()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onPlay)==null?void 0:e.call(t)},this.player.onpause=()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onPause)==null?void 0:e.call(t)},this.player.onended=()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onEnded)==null?void 0:e.call(t)},this.player.ontimeupdate=()=>{var t,e;(e=(t=this.options)==null?void 0:t.onTimeUpdate)==null||e.call(t,{duration:this.player.duration,percent:this.player.currentTime/this.player.duration,seconds:this.player.currentTime})}}async detach(){this.player.onerror=null,this.player.onloadeddata=null,this.player.onplay=null,this.player.onpause=null,this.player.onended=null,this.player.ontimeupdate=null}async loadVideo(t){this.player.src=t}async play(){this.player.play()}async pause(){this.player.pause()}async setCurrentTime(t){this.player.currentTime=t}async setVolume(t){this.player.volume=t}async setMuted(t){this.player.muted=t}async setPlaybackRate(t){this.player.playbackRate=t}async getDuration(){return this.player.duration}async getCurrentTime(){return this.player.currentTime}async getVolume(){return this.player.volume}async getPlaybackRate(){return this.player.playbackRate}}var S=(a=>(a.Audio="Audio",a.Dailymotion="Dailymotion",a.Niconico="Niconico",a.SoundCloud="SoundCloud",a.Twitch="Twitch",a.Vimeo="Vimeo",a.YouTube="YouTube",a))(S||{});function x(a){return S[a]!==void 0}const D=class D{constructor(t,e,r,i,l){g(this,"id");g(this,"impl");this.logger=t,this.type=e,this.player=r,this.options=i,this.playerApiFactory=l,this.id=D.nextId++}createMessage(t){return`${this.type}#${this.id} ${t}`}debug(t,...e){this.logger.log(u.Debug,this.createMessage(t),...e)}error(t,...e){this.logger.log(u.Error,this.createMessage(t),...e)}async attach(t){if(this.debug("attach",t),this.impl){this.debug("player is already attached");return}this.debug("Attaching player..."),this.impl=new this.playerApiFactory(this.logger,this.player,this.options),await this.impl.attach(t),this.debug("player attached")}createPlayerNotAttachedError(){return new Error("player is not attached")}async detach(){if(this.debug("detach"),this.impl===void 0)throw this.createPlayerNotAttachedError();await this.impl.detach(),this.impl=void 0}async loadVideo(t){if(this.debug("loadVideo",t),this.impl===void 0)throw this.createPlayerNotAttachedError();this.debug("Loading video..."),await this.impl.loadVideo(t),this.debug("video loaded",t)}play(){if(this.debug("play"),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.play()}pause(){if(this.debug("pause"),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.pause()}setCurrentTime(t){if(this.debug("setCurrentTime",t),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.setCurrentTime(t)}setVolume(t){if(this.debug("setVolume",t),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.setVolume(t)}setMuted(t){if(this.debug("setMuted",t),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.setMuted(t)}setPlaybackRate(t){if(this.debug("setPlaybackRate",t),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.setPlaybackRate(t)}getDuration(){if(this.debug("getDuration"),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.getDuration()}getCurrentTime(){if(this.debug("getCurrentTime"),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.getCurrentTime()}getVolume(){if(this.debug("getVolume"),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.getVolume()}getPlaybackRate(){if(this.debug("getPlaybackRate"),this.impl===void 0)throw this.createPlayerNotAttachedError();return this.impl.getPlaybackRate()}};g(D,"nextId",1);let C=D;function L(){const a=s.useRef(!0);return a.current?(a.current=!1,!0):a.current}const G=(a,t)=>a===t;function B(a,t=G){const e=s.useRef(),r=s.useRef(a);return!L()&&!t(r.current,a)&&(e.current=r.current,r.current=a),e.current}const E=({logger:a,type:t,loadScript:e,playerFactory:r,playerApiRef:i,videoId:l,options:o,playerApiFactory:n,children:d})=>{a.log(u.Debug,"PlayerContainer");const h=s.useRef(l),p=s.useRef(void 0),[b,P]=s.useState(),[m,v]=s.useState();s.useEffect(()=>{((e==null?void 0:e())??Promise.resolve()).then(()=>{r(p.current,h.current).then(y=>{P(y)})})},[e,r]),s.useEffect(()=>{if(b===void 0)return;const y=new C(a,t,b,o,n);return i&&(i.current=y),y.attach(h.current).then(()=>v(y)),()=>{if(i&&y!==i.current)throw new Error("playerApi differs");y.detach().finally(()=>v(void 0))}},[a,t,e,b,o,n,i]);const c=B(l);return s.useEffect(()=>{c!==void 0&&(m==null||m.loadVideo(l))},[c,l,m]),s.createElement(s.Fragment,null,d(p,h.current))},q=s.memo(({...a})=>{const{logger:t}=a;t.log(u.Debug,"AudioPlayer");const e=s.useCallback(r=>Promise.resolve(r),[]);return s.createElement(E,{...a,loadScript:void 0,playerFactory:e,playerApiFactory:M},(r,i)=>s.createElement("audio",{ref:r,src:i,style:{width:"100%",height:"100%"},preload:"auto",autoPlay:!0,controls:!0}))}),H=Object.freeze(Object.defineProperty({__proto__:null,default:q},Symbol.toStringTag,{value:"Module"})),N=["apiready","seeked","video_end","durationchange","pause","playing","error"];class U extends w{constructor(){super(...arguments);g(this,"handlePlayerEvents",e=>{var r,i,l,o,n,d,h,p,b,P,m,v;switch(e.type){case"apiready":(i=(r=this.options)==null?void 0:r.onLoaded)==null||i.call(r,{id:this.player.video.videoId});break;case"seeked":(o=(l=this.options)==null?void 0:l.onTimeUpdate)==null||o.call(l,{duration:this.player.duration,percent:this.player.currentTime/this.player.duration,seconds:this.player.currentTime});break;case"video_end":(d=(n=this.options)==null?void 0:n.onEnded)==null||d.call(n);break;case"durationchange":break;case"pause":(p=(h=this.options)==null?void 0:h.onPause)==null||p.call(h);break;case"playing":(P=(b=this.options)==null?void 0:b.onPlay)==null||P.call(b);break;case"error":(v=(m=this.options)==null?void 0:m.onError)==null||v.call(m,e);break}})}async attach(e){for(const r of N)this.player.addEventListener(r,this.handlePlayerEvents)}async detach(){for(const e of N)this.player.removeEventListener(e,this.handlePlayerEvents)}async loadVideo(e){this.player.load(e)}async play(){this.player.play()}async pause(){this.player.pause()}async setCurrentTime(e){this.player.seek(e)}async setVolume(e){this.player.setVolume(e)}async setMuted(e){this.player.setMuted(e)}async setPlaybackRate(e){}async getDuration(){return this.player.duration}async getCurrentTime(){return this.player.currentTime}async getVolume(){return this.player.volume}async getPlaybackRate(){return 1}}function K(a){return new Promise((t,e)=>{const r=document.createElement("script");r.src=a,r.async=!0,r.onerror=e,r.onload=r.onreadystatechange=function(){const i=this.readyState;i&&i!=="loaded"&&i!=="complete"||(r.onload=r.onreadystatechange=null,t())},document.head.appendChild(r)})}const A=[];async function T(a,t){if(A.includes(a))return t.log(u.Debug,a,"script is already loaded"),!1;try{return t.log(u.Debug,a,"Loading script..."),await K(a),A.includes(a)?(t.log(u.Debug,a,"script is already loaded"),!1):(A.push(a),t.log(u.Debug,a,"script loaded"),!0)}catch(e){throw t.log(u.Error,a,"Failed to load script"),e}}const J=s.memo(({options:a,...t})=>{const{logger:e}=t;e.log(u.Debug,"DailymotionPlayer");const r=s.useCallback(async()=>{await T("https://api.dmcdn.net/all.js",e)},[e]),i=s.useCallback((l,o)=>Promise.resolve(new DM.player(l,{video:o,width:"100%",height:"100%",events:{apiready:()=>{var n;(n=a==null?void 0:a.onLoaded)==null||n.call(a,{id:o})},seeked:()=>{var n;(n=a==null?void 0:a.onTimeUpdate)==null||n.call(a,{duration:0,percent:0,seconds:0})},video_end:()=>{var n;(n=a==null?void 0:a.onEnded)==null||n.call(a)},durationchange:()=>{},pause:()=>{var n;(n=a==null?void 0:a.onPause)==null||n.call(a)},playing:()=>{var n;(n=a==null?void 0:a.onPlay)==null||n.call(a)},waiting:()=>{},error:n=>{var d;(d=a==null?void 0:a.onError)==null||d.call(a,n)}}})),[a]);return s.createElement(E,{...t,options:a,loadScript:r,playerFactory:i,playerApiFactory:U},l=>s.createElement("div",{style:{width:"100%",height:"100%"}},s.createElement("div",{ref:l})))}),Q=Object.freeze(Object.defineProperty({__proto__:null,default:J},Symbol.toStringTag,{value:"Module"}));var R=(a=>(a[a.Play=2]="Play",a[a.Pause=3]="Pause",a[a.End=4]="End",a))(R||{});const f=class f extends w{constructor(){super(...arguments);g(this,"duration");g(this,"currentTime");g(this,"volume");g(this,"handleMessage",e=>{var i,l,o,n,d,h,p,b,P,m,v,c,y,I;if(e.origin!==f.origin)return;const r=e.data;switch(r.eventName){case"playerStatusChange":this.logger.log(u.Debug,`player status changed: ${R[r.data.playerStatus]??r.data.playerStatus}`);break;case"statusChange":switch(this.logger.log(u.Debug,`status changed: ${R[r.data.playerStatus]??r.data.playerStatus}`),r.data.playerStatus){case 2:(l=(i=this.options)==null?void 0:i.onPlay)==null||l.call(i);break;case 3:(n=(o=this.options)==null?void 0:o.onPause)==null||n.call(o);break;case 4:(h=(d=this.options)==null?void 0:d.onEnded)==null||h.call(d);break}break;case"playerMetadataChange":r.data.duration!==void 0&&(this.duration=r.data.duration/1e3),this.currentTime=r.data.currentTime===void 0?void 0:r.data.currentTime/1e3,this.volume=r.data.volume,(b=(p=this.options)==null?void 0:p.onTimeUpdate)==null||b.call(p,{duration:this.duration,percent:this.currentTime!==void 0&&this.duration!==void 0?this.currentTime/this.duration:void 0,seconds:this.currentTime});break;case"loadComplete":this.logger.log(u.Debug,"load completed"),this.duration=r.data.videoInfo.lengthInSeconds,(m=(P=this.options)==null?void 0:P.onLoaded)==null||m.call(P,{id:r.data.videoInfo.watchId});break;case"error":(c=(v=this.options)==null?void 0:v.onError)==null||c.call(v,r);break;case"player-error:video:play":case"player-error:video:seek":(I=(y=this.options)==null?void 0:y.onError)==null||I.call(y,r);break;default:this.logger.log(u.Debug,"message",r.eventName,r.data);break}})}async attach(){window.addEventListener("message",this.handleMessage)}async detach(){window.removeEventListener("message",this.handleMessage)}async loadVideo(e){return new Promise((r,i)=>{this.duration=void 0,this.currentTime=void 0,this.player.onload=()=>{this.player.onload=null,r()},this.player.src=`https://embed.nicovideo.jp/watch/${e}?jsapi=1&playerId=1`})}postMessage(e){var r;(r=this.player.contentWindow)==null||r.postMessage({...e,playerId:"1",sourceConnectorType:1},f.origin)}async play(){this.postMessage({eventName:"play"})}async pause(){this.postMessage({eventName:"pause"})}async setCurrentTime(e){this.postMessage({eventName:"seek",data:{time:e*1e3}})}async setVolume(e){this.postMessage({eventName:"volumeChange",data:{volume:e}})}async setMuted(e){this.postMessage({eventName:"mute",data:{mute:e}})}async setPlaybackRate(e){}async getDuration(){return this.duration}async getCurrentTime(){return this.currentTime}async getVolume(){return this.volume}async getPlaybackRate(){return 1}};g(f,"origin","https://embed.nicovideo.jp");let k=f;const X=s.memo(({...a})=>{const{logger:t}=a;t.log(u.Debug,"NiconicoPlayer");const e=s.useCallback(r=>Promise.resolve(r),[]);return s.createElement(E,{...a,loadScript:void 0,playerFactory:e,playerApiFactory:k},(r,i)=>s.createElement("div",{style:{width:"100%",height:"100%"}},s.createElement("iframe",{ref:r,src:`https://embed.nicovideo.jp/watch/${i}?jsapi=1&playerId=1`,width:"100%",height:"100%",allowFullScreen:!0,style:{border:"none"},allow:"autoplay; fullscreen"})))}),Z=Object.freeze(Object.defineProperty({__proto__:null,default:X},Symbol.toStringTag,{value:"Module"})),j=s.createContext(void 0),ee=new class{constructor(){g(this,"title","nostalgic-diva")}createMessage(a){return`[${this.title}] ${a}`}debug(a,...t){console.debug(this.createMessage(a),...t)}error(a,...t){console.error(this.createMessage(a),...t)}warn(a,...t){console.warn(this.createMessage(a),...t)}isEnabled(){return!0}log(a,t,...e){switch(a){case u.Debug:this.debug(t,...e);break;case u.Warning:this.warn(t,...e);break;case u.Error:this.error(t,...e);break}}},te=({logger:a=ee,children:t})=>{const e=s.useRef(),r=s.useCallback(async c=>{var y;await((y=e.current)==null?void 0:y.loadVideo(c))},[]),i=s.useCallback(async()=>{var c;await((c=e.current)==null?void 0:c.play())},[]),l=s.useCallback(async()=>{var c;await((c=e.current)==null?void 0:c.pause())},[]),o=s.useCallback(async c=>{const y=e.current;y&&(await y.setCurrentTime(c),await y.play())},[]),n=s.useCallback(async c=>{var y;await((y=e.current)==null?void 0:y.setVolume(c))},[]),d=s.useCallback(async c=>{var y;await((y=e.current)==null?void 0:y.setMuted(c))},[]),h=s.useCallback(async c=>{var y;await((y=e.current)==null?void 0:y.setPlaybackRate(c))},[]),p=s.useCallback(async()=>{var c;return await((c=e.current)==null?void 0:c.getDuration())},[]),b=s.useCallback(async()=>{var c;return await((c=e.current)==null?void 0:c.getCurrentTime())},[]),P=s.useCallback(async()=>{var c;return await((c=e.current)==null?void 0:c.getVolume())},[]),m=s.useCallback(async()=>{var c;return await((c=e.current)==null?void 0:c.getPlaybackRate())},[]),v=s.useMemo(()=>({logger:a,playerApiRef:e,loadVideo:r,play:i,pause:l,setCurrentTime:o,setVolume:n,setMuted:d,setPlaybackRate:h,getDuration:p,getCurrentTime:b,getVolume:P,getPlaybackRate:m}),[a,r,i,l,o,n,d,h,p,b,P,m]);return s.createElement(j.Provider,{value:v},t)},_=()=>s.useContext(j),ae=s.lazy(()=>Promise.resolve().then(()=>H)),re=s.lazy(()=>Promise.resolve().then(()=>Q)),se=s.lazy(()=>Promise.resolve().then(()=>Z)),ie=s.lazy(()=>Promise.resolve().then(()=>ye)),ne=s.lazy(()=>Promise.resolve().then(()=>pe)),oe=s.lazy(()=>Promise.resolve().then(()=>ve)),le=s.lazy(()=>Promise.resolve().then(()=>be)),ce={Audio:ae,Dailymotion:re,Niconico:se,SoundCloud:ie,Twitch:ne,Vimeo:oe,YouTube:le},ue=s.memo(({type:a,videoId:t,options:e})=>{const{logger:r,playerApiRef:i}=_();r.log(u.Debug,"NostalgicDiva");const l=ce[a];return s.createElement(s.Suspense,{fallback:null},s.createElement(l,{logger:r,type:a,playerApiRef:i,videoId:t,options:e}))});class V extends w{getDurationCore(){return new Promise((t,e)=>{this.player.getDuration(t)})}attach(t){return new Promise((e,r)=>{this.player.bind(SC.Widget.Events.READY,()=>{var i,l;this.player.bind(SC.Widget.Events.PLAY_PROGRESS,async o=>{var d,h;const n=await this.getDurationCore();(h=(d=this.options)==null?void 0:d.onTimeUpdate)==null||h.call(d,{duration:n/1e3,percent:o.currentPosition/n,seconds:o.currentPosition/1e3})}),this.player.bind(SC.Widget.Events.ERROR,o=>{var n,d;return(d=(n=this.options)==null?void 0:n.onError)==null?void 0:d.call(n,o)}),this.player.bind(SC.Widget.Events.PLAY,()=>{var o,n;return(n=(o=this.options)==null?void 0:o.onPlay)==null?void 0:n.call(o)}),this.player.bind(SC.Widget.Events.PAUSE,()=>{var o,n;return(n=(o=this.options)==null?void 0:o.onPause)==null?void 0:n.call(o)}),this.player.bind(SC.Widget.Events.FINISH,()=>{var o,n;return(n=(o=this.options)==null?void 0:o.onEnded)==null?void 0:n.call(o)}),(l=(i=this.options)==null?void 0:i.onLoaded)==null||l.call(i,{id:t}),e()})})}async detach(){this.player.unbind(SC.Widget.Events.READY),this.player.unbind(SC.Widget.Events.PLAY_PROGRESS),this.player.unbind(SC.Widget.Events.ERROR),this.player.unbind(SC.Widget.Events.PLAY),this.player.unbind(SC.Widget.Events.PAUSE),this.player.unbind(SC.Widget.Events.FINISH)}static playerLoadAsync(t,e,r){return new Promise((i,l)=>{t.load(e,{...r,callback:i})})}async loadVideo(t){var e,r;await V.playerLoadAsync(this.player,t,{auto_play:!0}),(r=(e=this.options)==null?void 0:e.onLoaded)==null||r.call(e,{id:t})}async play(){this.player.play()}async pause(){this.player.pause()}async setCurrentTime(t){this.player.seekTo(t*1e3)}async setVolume(t){this.player.setVolume(t*100)}async setMuted(t){this.setVolume(t?0:1)}async setPlaybackRate(t){}async getDuration(){return await this.getDurationCore()/1e3}getCurrentTimeCore(){return new Promise((t,e)=>{this.player.getPosition(t)})}async getCurrentTime(){return await this.getCurrentTimeCore()/1e3}getVolumeCore(){return new Promise((t,e)=>{this.player.getVolume(t)})}async getVolume(){return await this.getVolumeCore()/100}async getPlaybackRate(){return 1}}const de=s.memo(({...a})=>{const{logger:t}=a;t.log(u.Debug,"SoundCloudPlayer");const e=s.useCallback(async()=>{await T("https://w.soundcloud.com/player/api.js",t)},[t]),r=s.useCallback(i=>Promise.resolve(SC.Widget(i)),[]);return s.createElement(E,{...a,loadScript:e,playerFactory:r,playerApiFactory:V},(i,l)=>s.createElement("iframe",{ref:i,src:`https://w.soundcloud.com/player/?url=${l}`,frameBorder:0,allow:"autoplay",style:{width:"100%",height:"100%"}}))}),ye=Object.freeze(Object.defineProperty({__proto__:null,default:de},Symbol.toStringTag,{value:"Module"}));class F extends w{constructor(){super(...arguments);g(this,"handleReady",()=>{var e,r;(r=(e=this.options)==null?void 0:e.onLoaded)==null||r.call(e,{id:this.player.getVideo()})});g(this,"handlePlay",()=>{var e,r;(r=(e=this.options)==null?void 0:e.onPlay)==null||r.call(e)});g(this,"handlePause",()=>{var e,r;(r=(e=this.options)==null?void 0:e.onPause)==null||r.call(e)});g(this,"handleEnded",()=>{var e,r;(r=(e=this.options)==null?void 0:e.onEnded)==null||r.call(e)});g(this,"handleSeek",()=>{var e,r;(r=(e=this.options)==null?void 0:e.onTimeUpdate)==null||r.call(e,{duration:0,percent:0,seconds:0})})}async attach(e){this.player.addEventListener(Twitch.Player.READY,this.handleReady),this.player.addEventListener(Twitch.Player.PLAYING,this.handlePlay),this.player.addEventListener(Twitch.Player.PAUSE,this.handlePause),this.player.addEventListener(Twitch.Player.ENDED,this.handleEnded),this.player.addEventListener(Twitch.Player.SEEK,this.handleSeek)}async detach(){}async loadVideo(e){this.player.setVideo(e,0)}async play(){this.player.play()}async pause(){this.player.pause()}async setCurrentTime(e){this.player.seek(e)}async setVolume(e){this.player.setVolume(e)}async setMuted(e){this.player.setMuted(e)}async setPlaybackRate(e){}async getDuration(){return this.player.getDuration()}async getCurrentTime(){return this.player.getCurrentTime()}async getVolume(){return this.player.getVolume()}async getPlaybackRate(){return 1}}const he=s.memo(({...a})=>{const{logger:t}=a;t.log(u.Debug,"TwitchPlayer");const e=s.useCallback(async()=>{await T("https://embed.twitch.tv/embed/v1.js",t)},[t]),r=s.useCallback(async(i,l)=>Promise.resolve(new Twitch.Player(i,{video:l,width:"100%",height:"100%"})),[]);return s.createElement(E,{...a,loadScript:e,playerFactory:r,playerApiFactory:F},i=>s.createElement("div",{ref:i,style:{width:"100%",height:"100%"}}))}),pe=Object.freeze(Object.defineProperty({__proto__:null,default:he},Symbol.toStringTag,{value:"Module"}));var Y=(a=>(a[a.UNSTARTED=-1]="UNSTARTED",a[a.ENDED=0]="ENDED",a[a.PLAYING=1]="PLAYING",a[a.PAUSED=2]="PAUSED",a[a.BUFFERING=3]="BUFFERING",a[a.CUED=5]="CUED",a))(Y||{});class $ extends w{constructor(){super(...arguments);g(this,"previousTime");g(this,"timeUpdateIntervalId")}clearTimeUpdateInterval(){this.logger.log(u.Debug,"clearTimeUpdateInterval",this.timeUpdateIntervalId),window.clearInterval(this.timeUpdateIntervalId),this.timeUpdateIntervalId=void 0}invokeTimeUpdate(e){var l,o;const r=e.getCurrentTime();if(r===this.previousTime)return;const i=e.getDuration();(o=(l=this.options)==null?void 0:l.onTimeUpdate)==null||o.call(l,{duration:i,percent:r/i,seconds:r}),this.previousTime=r}setTimeUpdateInterval(){this.logger.log(u.Debug,"setTimeUpdateInterval"),this.clearTimeUpdateInterval(),this.timeUpdateIntervalId=window.setInterval(()=>this.invokeTimeUpdate(this.player),250),this.logger.log(u.Debug,"timeUpdateIntervalId",this.timeUpdateIntervalId),this.invokeTimeUpdate(this.player)}attach(e){return new Promise((r,i)=>{this.player.addEventListener("onReady",async()=>{this.player.addEventListener("onError",l=>{var o,n;return(n=(o=this.options)==null?void 0:o.onError)==null?void 0:n.call(o,l.data)}),this.player.addEventListener("onStateChange",l=>{var o,n,d,h,p,b,P,m;switch(this.logger.log(u.Debug,`state changed: ${Y[l.data]}`),l.data){case YT.PlayerState.CUED:(n=(o=this.options)==null?void 0:o.onLoaded)==null||n.call(o,{id:e});break;case YT.PlayerState.PLAYING:(h=(d=this.options)==null?void 0:d.onPlay)==null||h.call(d),this.setTimeUpdateInterval();break;case YT.PlayerState.PAUSED:(b=(p=this.options)==null?void 0:p.onPause)==null||b.call(p),this.clearTimeUpdateInterval();break;case YT.PlayerState.ENDED:(m=(P=this.options)==null?void 0:P.onEnded)==null||m.call(P),this.clearTimeUpdateInterval();break}}),await this.loadVideo(e),r()})})}async detach(){this.clearTimeUpdateInterval()}async loadVideo(e){this.previousTime=void 0,this.player.cueVideoById(e)}async play(){this.player.playVideo()}async pause(){this.player.pauseVideo()}async setCurrentTime(e){this.player.seekTo(e),this.invokeTimeUpdate(this.player)}async setVolume(e){this.player.setVolume(e*100)}async setMuted(e){e?this.player.mute():this.player.unMute()}async setPlaybackRate(e){this.player.setPlaybackRate(e)}async getDuration(){return this.player.getDuration()}async getCurrentTime(){return this.player.getCurrentTime()}async getVolume(){return this.player.getVolume()/100}async getPlaybackRate(){return this.player.getPlaybackRate()}}const me="https://www.youtube-nocookie.com",ge=s.memo(({...a})=>{const{logger:t}=a;t.log(u.Debug,"YouTubePlayer");const e=s.useCallback(()=>new Promise(async(i,l)=>{await T("https://www.youtube.com/iframe_api",t)?window.onYouTubeIframeAPIReady=()=>{t.log(u.Debug,"YouTube iframe API ready"),i()}:i()}),[t]),r=s.useCallback(i=>Promise.resolve(new YT.Player(i,{host:me,width:"100%",height:"100%"})),[]);return s.createElement(E,{...a,loadScript:e,playerFactory:r,playerApiFactory:$},i=>s.createElement("div",{style:{width:"100%",height:"100%"}},s.createElement("div",{ref:i})))}),be=Object.freeze(Object.defineProperty({__proto__:null,default:ge},Symbol.toStringTag,{value:"Module"}));class O extends w{async attach(){await this.player.ready(),this.player.on("error",t=>{var e,r;return(r=(e=this.options)==null?void 0:e.onError)==null?void 0:r.call(e,t)}),this.player.on("loaded",t=>{var e,r;return(r=(e=this.options)==null?void 0:e.onLoaded)==null?void 0:r.call(e,{id:t.id.toString()})}),this.player.on("play",()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onPlay)==null?void 0:e.call(t)}),this.player.on("pause",()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onPause)==null?void 0:e.call(t)}),this.player.on("ended",()=>{var t,e;return(e=(t=this.options)==null?void 0:t.onEnded)==null?void 0:e.call(t)}),this.player.on("timeupdate",t=>{var e,r;(r=(e=this.options)==null?void 0:e.onTimeUpdate)==null||r.call(e,{duration:t.duration,percent:t.percent,seconds:t.seconds})})}async detach(){this.player.off("error"),this.player.off("loaded"),this.player.off("play"),this.player.off("pause"),this.player.off("ended"),this.player.off("timeupdate")}async loadVideo(t){await this.player.loadVideo(t)}async play(){await this.player.play()}async pause(){await this.player.pause()}async setCurrentTime(t){await this.player.setCurrentTime(t)}async setVolume(t){await this.player.setVolume(t)}async setMuted(t){await this.player.setMuted(t)}async setPlaybackRate(t){await this.player.setPlaybackRate(t)}async getDuration(){return this.player.getDuration()}async getCurrentTime(){return this.player.getCurrentTime()}async getVolume(){return this.player.getVolume()}async getPlaybackRate(){return this.player.getPlaybackRate()}}const Pe=s.memo(({...a})=>{const{logger:t}=a;t.log(u.Debug,"VimeoPlayer");const e=s.useCallback(async()=>{await T("https://player.vimeo.com/api/player.js",t)},[t]),r=s.useCallback(i=>Promise.resolve(new Vimeo.Player(i)),[]);return s.createElement(E,{...a,loadScript:e,playerFactory:r,playerApiFactory:O},(i,l)=>s.createElement("iframe",{ref:i,src:`https://player.vimeo.com/video/${l}`,frameBorder:0,allow:"autoplay",style:{width:"100%",height:"100%"}}))}),ve=Object.freeze(Object.defineProperty({__proto__:null,default:Pe},Symbol.toStringTag,{value:"Module"}));exports.AudioPlayerApi=M;exports.DailymotionPlayerApi=U;exports.NiconicoPlayerApi=k;exports.NostalgicDiva=ue;exports.NostalgicDivaProvider=te;exports.PlayerApi=C;exports.PlayerType=S;exports.SoundCloudPlayerApi=V;exports.TwitchPlayerApi=F;exports.VimeoPlayerApi=O;exports.YouTubePlayerApi=$;exports.useNostalgicDiva=_;exports.validatePlayerType=x; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,5 +0,5 @@ | ||
var j = Object.defineProperty; | ||
var _ = (a, t, e) => t in a ? j(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e; | ||
var g = (a, t, e) => (_(a, typeof t != "symbol" ? t + "" : t, e), e); | ||
import s, { useRef as V } from "react"; | ||
var _ = Object.defineProperty; | ||
var F = (a, t, e) => t in a ? _(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e; | ||
var g = (a, t, e) => (F(a, typeof t != "symbol" ? t + "" : t, e), e); | ||
import s, { useRef as D } from "react"; | ||
var u = /* @__PURE__ */ ((a) => (a[a.Trace = 0] = "Trace", a[a.Debug = 1] = "Debug", a[a.Information = 2] = "Information", a[a.Warning = 3] = "Warning", a[a.Error = 4] = "Error", a[a.Critical = 5] = "Critical", a[a.None = 6] = "None", a))(u || {}); | ||
@@ -11,3 +11,3 @@ class w { | ||
} | ||
class F extends w { | ||
class Y extends w { | ||
async attach() { | ||
@@ -75,7 +75,11 @@ this.player.onerror = (t) => { | ||
} | ||
const A = class { | ||
var N = /* @__PURE__ */ ((a) => (a.Audio = "Audio", a.Dailymotion = "Dailymotion", a.Niconico = "Niconico", a.SoundCloud = "SoundCloud", a.Twitch = "Twitch", a.Vimeo = "Vimeo", a.YouTube = "YouTube", a))(N || {}); | ||
function we(a) { | ||
return N[a] !== void 0; | ||
} | ||
const C = class C { | ||
constructor(t, e, r, i, l) { | ||
g(this, "id"); | ||
g(this, "impl"); | ||
this.logger = t, this.type = e, this.player = r, this.options = i, this.playerApiFactory = l, this.id = A.nextId++; | ||
this.logger = t, this.type = e, this.player = r, this.options = i, this.playerApiFactory = l, this.id = C.nextId++; | ||
} | ||
@@ -174,11 +178,11 @@ createMessage(t) { | ||
}; | ||
let T = A; | ||
g(T, "nextId", 1); | ||
g(C, "nextId", 1); | ||
let V = C; | ||
function $() { | ||
const a = V(!0); | ||
const a = D(!0); | ||
return a.current ? (a.current = !1, !0) : a.current; | ||
} | ||
const Y = (a, t) => a === t; | ||
function O(a, t = Y) { | ||
const e = V(), r = V(a); | ||
const O = (a, t) => a === t; | ||
function W(a, t = O) { | ||
const e = D(), r = D(a); | ||
return !$() && !t(r.current, a) && (e.current = r.current, r.current = a), e.current; | ||
@@ -198,8 +202,8 @@ } | ||
a.log(u.Debug, "PlayerContainer"); | ||
const h = s.useRef(l), p = s.useRef(void 0), [b, P] = s.useState(), [m, v] = s.useState(); | ||
const y = s.useRef(l), p = s.useRef(void 0), [b, v] = s.useState(), [m, P] = s.useState(); | ||
s.useEffect(() => { | ||
((e == null ? void 0 : e()) ?? Promise.resolve()).then(() => { | ||
r(p.current, h.current).then( | ||
(y) => { | ||
P(y); | ||
r(p.current, y.current).then( | ||
(h) => { | ||
v(h); | ||
} | ||
@@ -211,3 +215,3 @@ ); | ||
return; | ||
const y = new T( | ||
const h = new V( | ||
a, | ||
@@ -219,6 +223,6 @@ t, | ||
); | ||
return i && (i.current = y), y.attach(h.current).then(() => v(y)), () => { | ||
if (i && y !== i.current) | ||
return i && (i.current = h), h.attach(y.current).then(() => P(h)), () => { | ||
if (i && h !== i.current) | ||
throw new Error("playerApi differs"); | ||
y.detach().finally(() => v(void 0)); | ||
h.detach().finally(() => P(void 0)); | ||
}; | ||
@@ -234,7 +238,7 @@ }, [ | ||
]); | ||
const c = O(l); | ||
const c = W(l); | ||
return s.useEffect(() => { | ||
c !== void 0 && (m == null || m.loadVideo(l)); | ||
}, [c, l, m]), /* @__PURE__ */ s.createElement(s.Fragment, null, d(p, h.current)); | ||
}, W = s.memo( | ||
}, [c, l, m]), /* @__PURE__ */ s.createElement(s.Fragment, null, d(p, y.current)); | ||
}, z = s.memo( | ||
({ ...a }) => { | ||
@@ -253,3 +257,3 @@ const { logger: t } = a; | ||
playerFactory: e, | ||
playerApiFactory: F | ||
playerApiFactory: Y | ||
}, | ||
@@ -269,5 +273,5 @@ (r, i) => /* @__PURE__ */ s.createElement( | ||
} | ||
), z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
), x = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
__proto__: null, | ||
default: W | ||
default: z | ||
}, Symbol.toStringTag, { value: "Module" })), M = [ | ||
@@ -282,7 +286,7 @@ "apiready", | ||
]; | ||
class x extends w { | ||
class L extends w { | ||
constructor() { | ||
super(...arguments); | ||
g(this, "handlePlayerEvents", (e) => { | ||
var r, i, l, o, n, d, h, p, b, P, m, v; | ||
var r, i, l, o, n, d, y, p, b, v, m, P; | ||
switch (e.type) { | ||
@@ -305,9 +309,9 @@ case "apiready": | ||
case "pause": | ||
(p = (h = this.options) == null ? void 0 : h.onPause) == null || p.call(h); | ||
(p = (y = this.options) == null ? void 0 : y.onPause) == null || p.call(y); | ||
break; | ||
case "playing": | ||
(P = (b = this.options) == null ? void 0 : b.onPlay) == null || P.call(b); | ||
(v = (b = this.options) == null ? void 0 : b.onPlay) == null || v.call(b); | ||
break; | ||
case "error": | ||
(v = (m = this.options) == null ? void 0 : m.onError) == null || v.call(m, e); | ||
(P = (m = this.options) == null ? void 0 : m.onError) == null || P.call(m, e); | ||
break; | ||
@@ -358,3 +362,3 @@ } | ||
} | ||
function L(a) { | ||
function G(a) { | ||
return new Promise((t, e) => { | ||
@@ -368,8 +372,8 @@ const r = document.createElement("script"); | ||
} | ||
const D = []; | ||
async function f(a, t) { | ||
if (D.includes(a)) | ||
const k = []; | ||
async function T(a, t) { | ||
if (k.includes(a)) | ||
return t.log(u.Debug, a, "script is already loaded"), !1; | ||
try { | ||
return t.log(u.Debug, a, "Loading script..."), await L(a), D.includes(a) ? (t.log(u.Debug, a, "script is already loaded"), !1) : (D.push(a), t.log(u.Debug, a, "script loaded"), !0); | ||
return t.log(u.Debug, a, "Loading script..."), await G(a), k.includes(a) ? (t.log(u.Debug, a, "script is already loaded"), !1) : (k.push(a), t.log(u.Debug, a, "script loaded"), !0); | ||
} catch (e) { | ||
@@ -379,3 +383,3 @@ throw t.log(u.Error, a, "Failed to load script"), e; | ||
} | ||
const G = s.memo( | ||
const B = s.memo( | ||
({ options: a, ...t }) => { | ||
@@ -385,3 +389,3 @@ const { logger: e } = t; | ||
const r = s.useCallback(async () => { | ||
await f("https://api.dmcdn.net/all.js", e); | ||
await T("https://api.dmcdn.net/all.js", e); | ||
}, [e]), i = s.useCallback( | ||
@@ -438,3 +442,3 @@ (l, o) => Promise.resolve( | ||
playerFactory: i, | ||
playerApiFactory: x | ||
playerApiFactory: L | ||
}, | ||
@@ -444,8 +448,8 @@ (l) => /* @__PURE__ */ s.createElement("div", { style: { width: "100%", height: "100%" } }, /* @__PURE__ */ s.createElement("div", { ref: l })) | ||
} | ||
), B = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
), H = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
__proto__: null, | ||
default: G | ||
default: B | ||
}, Symbol.toStringTag, { value: "Module" })); | ||
var R = /* @__PURE__ */ ((a) => (a[a.Play = 2] = "Play", a[a.Pause = 3] = "Pause", a[a.End = 4] = "End", a))(R || {}); | ||
const C = class extends w { | ||
const f = class f extends w { | ||
constructor() { | ||
@@ -457,4 +461,4 @@ super(...arguments); | ||
g(this, "handleMessage", (e) => { | ||
var i, l, o, n, d, h, p, b, P, m, v, c, y, I; | ||
if (e.origin !== C.origin) | ||
var i, l, o, n, d, y, p, b, v, m, P, c, h, I; | ||
if (e.origin !== f.origin) | ||
return; | ||
@@ -481,3 +485,3 @@ const r = e.data; | ||
case 4: | ||
(h = (d = this.options) == null ? void 0 : d.onEnded) == null || h.call(d); | ||
(y = (d = this.options) == null ? void 0 : d.onEnded) == null || y.call(d); | ||
break; | ||
@@ -494,10 +498,10 @@ } | ||
case "loadComplete": | ||
this.logger.log(u.Debug, "load completed"), this.duration = r.data.videoInfo.lengthInSeconds, (m = (P = this.options) == null ? void 0 : P.onLoaded) == null || m.call(P, { id: r.data.videoInfo.watchId }); | ||
this.logger.log(u.Debug, "load completed"), this.duration = r.data.videoInfo.lengthInSeconds, (m = (v = this.options) == null ? void 0 : v.onLoaded) == null || m.call(v, { id: r.data.videoInfo.watchId }); | ||
break; | ||
case "error": | ||
(c = (v = this.options) == null ? void 0 : v.onError) == null || c.call(v, r); | ||
(c = (P = this.options) == null ? void 0 : P.onError) == null || c.call(P, r); | ||
break; | ||
case "player-error:video:play": | ||
case "player-error:video:seek": | ||
(I = (y = this.options) == null ? void 0 : y.onError) == null || I.call(y, r); | ||
(I = (h = this.options) == null ? void 0 : h.onError) == null || I.call(h, r); | ||
break; | ||
@@ -537,3 +541,3 @@ default: | ||
}, | ||
C.origin | ||
f.origin | ||
); | ||
@@ -577,5 +581,5 @@ } | ||
}; | ||
let k = C; | ||
g(k, "origin", "https://embed.nicovideo.jp"); | ||
const H = s.memo( | ||
g(f, "origin", "https://embed.nicovideo.jp"); | ||
let S = f; | ||
const q = s.memo( | ||
({ ...a }) => { | ||
@@ -594,3 +598,3 @@ const { logger: t } = a; | ||
playerFactory: e, | ||
playerApiFactory: k | ||
playerApiFactory: S | ||
}, | ||
@@ -611,9 +615,9 @@ (r, i) => /* @__PURE__ */ s.createElement("div", { style: { width: "100%", height: "100%" } }, /* @__PURE__ */ s.createElement( | ||
} | ||
), q = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
), K = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
__proto__: null, | ||
default: H | ||
}, Symbol.toStringTag, { value: "Module" })), N = s.createContext( | ||
default: q | ||
}, Symbol.toStringTag, { value: "Module" })), U = s.createContext( | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
void 0 | ||
), K = new class { | ||
), J = new class { | ||
constructor() { | ||
@@ -650,9 +654,9 @@ g(this, "title", "nostalgic-diva"); | ||
} | ||
}(), ve = ({ | ||
logger: a = K, | ||
}(), Ee = ({ | ||
logger: a = J, | ||
children: t | ||
}) => { | ||
const e = s.useRef(), r = s.useCallback(async (c) => { | ||
var y; | ||
await ((y = e.current) == null ? void 0 : y.loadVideo(c)); | ||
var h; | ||
await ((h = e.current) == null ? void 0 : h.loadVideo(c)); | ||
}, []), i = s.useCallback(async () => { | ||
@@ -665,13 +669,13 @@ var c; | ||
}, []), o = s.useCallback(async (c) => { | ||
const y = e.current; | ||
y && (await y.setCurrentTime(c), await y.play()); | ||
const h = e.current; | ||
h && (await h.setCurrentTime(c), await h.play()); | ||
}, []), n = s.useCallback(async (c) => { | ||
var y; | ||
await ((y = e.current) == null ? void 0 : y.setVolume(c)); | ||
var h; | ||
await ((h = e.current) == null ? void 0 : h.setVolume(c)); | ||
}, []), d = s.useCallback(async (c) => { | ||
var y; | ||
await ((y = e.current) == null ? void 0 : y.setMuted(c)); | ||
}, []), h = s.useCallback(async (c) => { | ||
var y; | ||
await ((y = e.current) == null ? void 0 : y.setPlaybackRate(c)); | ||
var h; | ||
await ((h = e.current) == null ? void 0 : h.setMuted(c)); | ||
}, []), y = s.useCallback(async (c) => { | ||
var h; | ||
await ((h = e.current) == null ? void 0 : h.setPlaybackRate(c)); | ||
}, []), p = s.useCallback(async () => { | ||
@@ -683,3 +687,3 @@ var c; | ||
return await ((c = e.current) == null ? void 0 : c.getCurrentTime()); | ||
}, []), P = s.useCallback(async () => { | ||
}, []), v = s.useCallback(async () => { | ||
var c; | ||
@@ -690,3 +694,3 @@ return await ((c = e.current) == null ? void 0 : c.getVolume()); | ||
return await ((c = e.current) == null ? void 0 : c.getPlaybackRate()); | ||
}, []), v = s.useMemo( | ||
}, []), P = s.useMemo( | ||
() => ({ | ||
@@ -701,6 +705,6 @@ logger: a, | ||
setMuted: d, | ||
setPlaybackRate: h, | ||
setPlaybackRate: y, | ||
getDuration: p, | ||
getCurrentTime: b, | ||
getVolume: P, | ||
getVolume: v, | ||
getPlaybackRate: m | ||
@@ -716,23 +720,23 @@ }), | ||
d, | ||
h, | ||
y, | ||
p, | ||
b, | ||
P, | ||
v, | ||
m | ||
] | ||
); | ||
return /* @__PURE__ */ s.createElement(N.Provider, { value: v }, t); | ||
}, J = () => s.useContext(N), Q = s.lazy(() => Promise.resolve().then(() => z)), X = s.lazy(() => Promise.resolve().then(() => B)), Z = s.lazy(() => Promise.resolve().then(() => q)), ee = s.lazy(() => Promise.resolve().then(() => ne)), te = s.lazy(() => Promise.resolve().then(() => ce)), ae = s.lazy(() => Promise.resolve().then(() => ge)), re = s.lazy(() => Promise.resolve().then(() => he)), se = { | ||
Audio: Q, | ||
Dailymotion: X, | ||
Niconico: Z, | ||
SoundCloud: ee, | ||
Twitch: te, | ||
Vimeo: ae, | ||
YouTube: re | ||
}, we = s.memo( | ||
return /* @__PURE__ */ s.createElement(U.Provider, { value: P }, t); | ||
}, Q = () => s.useContext(U), X = s.lazy(() => Promise.resolve().then(() => x)), Z = s.lazy(() => Promise.resolve().then(() => H)), ee = s.lazy(() => Promise.resolve().then(() => K)), te = s.lazy(() => Promise.resolve().then(() => oe)), ae = s.lazy(() => Promise.resolve().then(() => ue)), re = s.lazy(() => Promise.resolve().then(() => be)), se = s.lazy(() => Promise.resolve().then(() => pe)), ie = { | ||
Audio: X, | ||
Dailymotion: Z, | ||
Niconico: ee, | ||
SoundCloud: te, | ||
Twitch: ae, | ||
Vimeo: re, | ||
YouTube: se | ||
}, fe = s.memo( | ||
({ type: a, videoId: t, options: e }) => { | ||
const { logger: r, playerApiRef: i } = J(); | ||
const { logger: r, playerApiRef: i } = Q(); | ||
r.log(u.Debug, "NostalgicDiva"); | ||
const l = se[a]; | ||
const l = ie[a]; | ||
return /* @__PURE__ */ s.createElement(s.Suspense, { fallback: null }, /* @__PURE__ */ s.createElement( | ||
@@ -750,3 +754,3 @@ l, | ||
); | ||
class S extends w { | ||
class A extends w { | ||
getDurationCore() { | ||
@@ -764,5 +768,5 @@ return new Promise((t, e) => { | ||
async (o) => { | ||
var d, h; | ||
var d, y; | ||
const n = await this.getDurationCore(); | ||
(h = (d = this.options) == null ? void 0 : d.onTimeUpdate) == null || h.call(d, { | ||
(y = (d = this.options) == null ? void 0 : d.onTimeUpdate) == null || y.call(d, { | ||
duration: n / 1e3, | ||
@@ -811,3 +815,3 @@ percent: o.currentPosition / n, | ||
var e, r; | ||
await S.playerLoadAsync(this.player, t, { | ||
await A.playerLoadAsync(this.player, t, { | ||
auto_play: !0 | ||
@@ -859,3 +863,3 @@ }), (r = (e = this.options) == null ? void 0 : e.onLoaded) == null || r.call(e, { id: t }); | ||
} | ||
const ie = s.memo( | ||
const ne = s.memo( | ||
({ ...a }) => { | ||
@@ -865,3 +869,3 @@ const { logger: t } = a; | ||
const e = s.useCallback(async () => { | ||
await f( | ||
await T( | ||
"https://w.soundcloud.com/player/api.js", | ||
@@ -880,3 +884,3 @@ t | ||
playerFactory: r, | ||
playerApiFactory: S | ||
playerApiFactory: A | ||
}, | ||
@@ -898,7 +902,7 @@ (i, l) => ( | ||
} | ||
), ne = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
), oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
__proto__: null, | ||
default: ie | ||
default: ne | ||
}, Symbol.toStringTag, { value: "Module" })); | ||
class oe extends w { | ||
class le extends w { | ||
constructor() { | ||
@@ -969,3 +973,3 @@ super(...arguments); | ||
} | ||
const le = s.memo( | ||
const ce = s.memo( | ||
({ ...a }) => { | ||
@@ -975,3 +979,3 @@ const { logger: t } = a; | ||
const e = s.useCallback(async () => { | ||
await f( | ||
await T( | ||
"https://embed.twitch.tv/embed/v1.js", | ||
@@ -996,3 +1000,3 @@ t | ||
playerFactory: r, | ||
playerApiFactory: oe | ||
playerApiFactory: le | ||
}, | ||
@@ -1008,8 +1012,8 @@ (i) => /* @__PURE__ */ s.createElement( | ||
} | ||
), ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
), ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
__proto__: null, | ||
default: le | ||
default: ce | ||
}, Symbol.toStringTag, { value: "Module" })); | ||
var U = /* @__PURE__ */ ((a) => (a[a.UNSTARTED = -1] = "UNSTARTED", a[a.ENDED = 0] = "ENDED", a[a.PLAYING = 1] = "PLAYING", a[a.PAUSED = 2] = "PAUSED", a[a.BUFFERING = 3] = "BUFFERING", a[a.CUED = 5] = "CUED", a))(U || {}); | ||
class ue extends w { | ||
var j = /* @__PURE__ */ ((a) => (a[a.UNSTARTED = -1] = "UNSTARTED", a[a.ENDED = 0] = "ENDED", a[a.PLAYING = 1] = "PLAYING", a[a.PAUSED = 2] = "PAUSED", a[a.BUFFERING = 3] = "BUFFERING", a[a.CUED = 5] = "CUED", a))(j || {}); | ||
class de extends w { | ||
constructor() { | ||
@@ -1061,6 +1065,6 @@ super(...arguments); | ||
(l) => { | ||
var o, n, d, h, p, b, P, m; | ||
var o, n, d, y, p, b, v, m; | ||
switch (this.logger.log( | ||
u.Debug, | ||
`state changed: ${U[l.data]}` | ||
`state changed: ${j[l.data]}` | ||
), l.data) { | ||
@@ -1071,3 +1075,3 @@ case YT.PlayerState.CUED: | ||
case YT.PlayerState.PLAYING: | ||
(h = (d = this.options) == null ? void 0 : d.onPlay) == null || h.call(d), this.setTimeUpdateInterval(); | ||
(y = (d = this.options) == null ? void 0 : d.onPlay) == null || y.call(d), this.setTimeUpdateInterval(); | ||
break; | ||
@@ -1078,3 +1082,3 @@ case YT.PlayerState.PAUSED: | ||
case YT.PlayerState.ENDED: | ||
(m = (P = this.options) == null ? void 0 : P.onEnded) == null || m.call(P), this.clearTimeUpdateInterval(); | ||
(m = (v = this.options) == null ? void 0 : v.onEnded) == null || m.call(v), this.clearTimeUpdateInterval(); | ||
break; | ||
@@ -1124,3 +1128,3 @@ } | ||
} | ||
const de = "https://www.youtube-nocookie.com", ye = s.memo( | ||
const he = "https://www.youtube-nocookie.com", ye = s.memo( | ||
({ ...a }) => { | ||
@@ -1130,3 +1134,3 @@ const { logger: t } = a; | ||
const e = s.useCallback(() => new Promise(async (i, l) => { | ||
await f( | ||
await T( | ||
"https://www.youtube.com/iframe_api", | ||
@@ -1140,3 +1144,3 @@ t | ||
new YT.Player(i, { | ||
host: de, | ||
host: he, | ||
width: "100%", | ||
@@ -1154,3 +1158,3 @@ height: "100%" | ||
playerFactory: r, | ||
playerApiFactory: ue | ||
playerApiFactory: de | ||
}, | ||
@@ -1160,7 +1164,7 @@ (i) => /* @__PURE__ */ s.createElement("div", { style: { width: "100%", height: "100%" } }, /* @__PURE__ */ s.createElement("div", { ref: i })) | ||
} | ||
), he = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
), pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
__proto__: null, | ||
default: ye | ||
}, Symbol.toStringTag, { value: "Module" })); | ||
class pe extends w { | ||
class me extends w { | ||
async attach() { | ||
@@ -1231,3 +1235,3 @@ await this.player.ready(), this.player.on("error", (t) => { | ||
} | ||
const me = s.memo( | ||
const ge = s.memo( | ||
({ ...a }) => { | ||
@@ -1237,3 +1241,3 @@ const { logger: t } = a; | ||
const e = s.useCallback(async () => { | ||
await f( | ||
await T( | ||
"https://player.vimeo.com/api/player.js", | ||
@@ -1252,3 +1256,3 @@ t | ||
playerFactory: r, | ||
playerApiFactory: pe | ||
playerApiFactory: me | ||
}, | ||
@@ -1270,19 +1274,21 @@ (i, l) => ( | ||
} | ||
), ge = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
), be = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ | ||
__proto__: null, | ||
default: me | ||
default: ge | ||
}, Symbol.toStringTag, { value: "Module" })); | ||
export { | ||
F as AudioPlayerApi, | ||
x as DailymotionPlayerApi, | ||
k as NiconicoPlayerApi, | ||
we as NostalgicDiva, | ||
ve as NostalgicDivaProvider, | ||
T as PlayerApi, | ||
S as SoundCloudPlayerApi, | ||
oe as TwitchPlayerApi, | ||
pe as VimeoPlayerApi, | ||
ue as YouTubePlayerApi, | ||
J as useNostalgicDiva | ||
Y as AudioPlayerApi, | ||
L as DailymotionPlayerApi, | ||
S as NiconicoPlayerApi, | ||
fe as NostalgicDiva, | ||
Ee as NostalgicDivaProvider, | ||
V as PlayerApi, | ||
N as PlayerType, | ||
A as SoundCloudPlayerApi, | ||
le as TwitchPlayerApi, | ||
me as VimeoPlayerApi, | ||
de as YouTubePlayerApi, | ||
Q as useNostalgicDiva, | ||
we as validatePlayerType | ||
}; | ||
//# sourceMappingURL=index.es.js.map |
import { ILogger } from './ILogger'; | ||
import { PlayerApiImpl } from './PlayerApiImpl'; | ||
export type PlayerType = 'Audio' | 'Dailymotion' | 'Niconico' | 'SoundCloud' | 'Twitch' | 'Vimeo' | 'YouTube'; | ||
export declare enum PlayerType { | ||
'Audio' = "Audio", | ||
'Dailymotion' = "Dailymotion", | ||
'Niconico' = "Niconico", | ||
'SoundCloud' = "SoundCloud", | ||
'Twitch' = "Twitch", | ||
'Vimeo' = "Vimeo", | ||
'YouTube' = "YouTube" | ||
} | ||
export declare function validatePlayerType(value: string): value is PlayerType; | ||
export interface LoadedEvent { | ||
@@ -42,3 +51,3 @@ id: string; | ||
private impl?; | ||
constructor(logger: ILogger, type: PlayerType, player: TPlayer, options: PlayerOptions | undefined, playerApiFactory: new (logger: ILogger, player: TPlayer, options: PlayerOptions | undefined) => TPlayerApi); | ||
constructor(logger: ILogger, type: `${PlayerType}`, player: TPlayer, options: PlayerOptions | undefined, playerApiFactory: new (logger: ILogger, player: TPlayer, options: PlayerOptions | undefined) => TPlayerApi); | ||
private createMessage; | ||
@@ -45,0 +54,0 @@ debug(message?: any, ...optionalParams: any): void; |
{ | ||
"name": "@aigamo/nostalgic-diva", | ||
"version": "1.8.0", | ||
"version": "1.9.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
255561
1709