@@ -13,44 +13,24 @@ const YOUTUBE_WWW_SHORT_DOMAIN = "www.youtu.be";
1313const VIMEO_DOMAIN = "vimeo.com" ;
1414const VIMEO_WWW_DOMAIN = "www.vimeo.com" ;
1515
16- interface VideoEmbedQuery {
17- loop ?: number ;
18- autoplay ?: number ;
19- modestbranding ?: number ;
20- title ?: number ;
21- byline ?: number ;
22- portait ?: number ;
23- badge ?: number ;
24- [ propName : string ] : number ;
16+ interface QueryParams {
17+ [ propName : string ] : string ;
2518}
2619
27- export const queryParams = (
28- src : string
29- ) => {
30- const queryObject = { } ;
31-
32- src . substr ( 1 )
33- . split ( '&' )
34- . forEach ( field => {
35- const keyValue = field . split ( '=' ) ;
36- queryObject [ decodeURIComponent ( keyValue [ 0 ] ) ] = decodeURIComponent ( keyValue [ 1 ] ) ;
37- } ) ;
38-
39- return queryObject ;
40- }
41-
42- const buildUrl = (
43- src : string ,
44- query : VideoEmbedQuery ,
45- ) => {
46- return [
47- src ,
48- '?' ,
49- Object . keys ( query )
50- . map ( key => encodeURIComponent ( key ) + '=' + encodeURIComponent ( query [ key ] . toString ( ) ) )
51- . join ( '&' )
52- ] . join ( '' ) ;
53- }
20+ export const queryParams = ( src : string ) =>
21+ src
22+ . substr ( 1 )
23+ . split ( '&' )
24+ . reduce ( ( previous , current ) => {
25+ const keyValue = current . split ( '=' ) ;
26+ previous [ decodeURIComponent ( keyValue [ 0 ] ) ] = decodeURIComponent ( keyValue [ 1 ] ) ;
27+ return previous ;
28+ } , { } as QueryParams ) ;
29+
30+ const queryString = ( query : QueryParams ) =>
31+ Object . keys ( query )
32+ . map ( key => encodeURIComponent ( key ) + '=' + encodeURIComponent ( query [ key ] . toString ( ) ) )
33+ . join ( '&' ) ;
5434
5535const buttons = (
5636 buttons : Button [ ] ,
@@ -67,16 +47,11 @@ const Youtube = (props: {
6747} ) =>
6848 < iframe
6949 type = "text/html"
70- src = {
71- buildUrl (
72- `https://${ YOUTUBE_DOMAIN } /embed/${ props . embedId } ` ,
73- {
74- modestbranding : 1 ,
75- loop : props . loop ? 1 : 0 ,
76- autoplay : props . autoPlay ? 1 : 0
77- }
78- )
79- }
50+ src = { `https://${ YOUTUBE_DOMAIN } /embed/${ props . embedId } ?${ queryString ( {
51+ modestbranding : '1' ,
52+ loop : props . loop ? '1' : '0' ,
53+ autoplay : props . autoPlay ? '1' : '0'
54+ } ) } ` }
8055 /> ;
8156
8257const Vimeo = ( props : {
@@ -86,19 +61,14 @@ const Vimeo = (props: {
8661} ) =>
8762 < iframe
8863 type = "text/html"
89- src = {
90- buildUrl (
91- `https://player.${ VIMEO_DOMAIN } /video/${ props . embedId } ` ,
92- {
93- title : 0 ,
94- byline : 0 ,
95- portrait : 0 ,
96- badge : 0 ,
97- autoplay : props . autoPlay ? 1 : 0 ,
98- loop : props . loop ? 1 : 0
99- }
100- )
101- }
64+ src = { `https://player.${ VIMEO_DOMAIN } /video/${ props . embedId } ?${ queryString ( {
65+ title : '0' ,
66+ byline : '0' ,
67+ portrait : '0' ,
68+ badge : '0' ,
69+ autoplay : props . autoPlay ? '1' : '0' ,
70+ loop : props . loop ? '1' : '0'
71+ } ) } ` }
10272 /> ;
10373
10474const Video = ( props : {
0 commit comments