@@ -77,7 +77,7 @@ export default {
77
77
return {
78
78
playing : false ,
79
79
scrubbing : false ,
80
- aspectRatioPercentage : '' ,
80
+ aspectRatio : 1 ,
81
81
duration : 0 ,
82
82
elapsed : 0 ,
83
83
lastTime : 0 ,
@@ -115,7 +115,7 @@ export default {
115
115
const { video } = this . $refs
116
116
this . width = video . videoWidth
117
117
this . height = video . videoHeight
118
- this . aspectRatioPercentage = ` ${ ( this . height / this . width ) * 100 } %`
118
+ this . aspectRatio = this . height / this . width
119
119
} ,
120
120
play ( e ) {
121
121
if ( e ) e . stopPropagation ( )
@@ -191,9 +191,16 @@ export default {
191
191
} ,
192
192
computed : {
193
193
computedWrapStyles ( ) {
194
- return ( this . cover )
195
- ? Object . assign ( { } , videoWrapInnerStyles , mediaCoveringStyles )
196
- : { paddingBottom : this . aspectRatioPercentage , ...videoWrapInnerStyles }
194
+ const base = { paddingBottom : `${ this . aspectRatio * 100 } %` , ...videoWrapInnerStyles }
195
+ const centerSquare = { marginTop : `${ ( 1 - this . aspectRatio ) / 2 * 100 } %` }
196
+
197
+ if ( this . cover && ! this . square ) {
198
+ return Object . assign ( { } , videoWrapInnerStyles , mediaCoveringStyles )
199
+ } else if ( this . square && ! this . cover ) {
200
+ return Object . assign ( { } , base , centerSquare )
201
+ }
202
+
203
+ return base
197
204
} ,
198
205
computedVideoStyles ( ) {
199
206
const cover = Object . assign ( { } , videoStyles , mediaCoveringStyles )
@@ -211,8 +218,12 @@ export default {
211
218
}
212
219
} ,
213
220
mounted ( ) {
214
- this . init ( )
215
- this . bind ( )
221
+ if ( this . cover && this . square ) {
222
+ console . error ( '[vue-canvasvideo]: The cover and square props cannot be used together.' )
223
+ } else {
224
+ this . init ( )
225
+ this . bind ( )
226
+ }
216
227
} ,
217
228
props : {
218
229
src : {
@@ -231,6 +242,10 @@ export default {
231
242
type : Boolean ,
232
243
default : ( ) => false
233
244
} ,
245
+ square : {
246
+ type : Boolean ,
247
+ default : ( ) => false
248
+ } ,
234
249
loop : {
235
250
type : Boolean ,
236
251
default : ( ) => false
0 commit comments