Skip to content
Prev Previous commit
Next Next commit
refactor: replace VideoElement extension to apply default styles with…
… a method
  • Loading branch information
bselwe committed Jul 9, 2021
commit 2b9379000009a24d44574f611c51d5ac3ac4604a
24 changes: 11 additions & 13 deletions packages/camera/camera_web/lib/src/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class Camera {
);
}

videoElement = html.VideoElement()..applyDefaultStyles();
videoElement = html.VideoElement();
_applyDefaultVideoStyles(videoElement);

divElement = html.DivElement()
..style.setProperty('object-fit', 'cover')
..append(videoElement);
Expand Down Expand Up @@ -135,18 +137,14 @@ class Camera {
..srcObject = null
..load();
}
}

extension on html.VideoElement {
void applyDefaultStyles() {
style
..removeProperty('transform-origin')
..setProperty('pointer-events', 'none')
..setProperty('width', '100%')
..setProperty('height', '100%')
..setProperty('object-fit', 'cover')
..setProperty('transform', 'scaleX(-1)')
..setProperty('-webkit-transform', 'scaleX(-1)')
..setProperty('-moz-transform', 'scaleX(-1)');
void _applyDefaultVideoStyles(html.VideoElement element) {
element.style
..transformOrigin = 'center'
..pointerEvents = 'none'
..width = '100%'
..height = '100%'
..objectFit = 'cover'
..transform = 'scaleX(-1)';
}
}