Add bindings for HTMLVideoElement.videoHeight and videoWidth

pull/3927/head
Mattias Buelens 5 years ago
parent 79d3763e92
commit f2f87d126c

@ -13,7 +13,9 @@ const read_only_media_attributes = new Set([
'seekable', 'seekable',
'played', 'played',
'seeking', 'seeking',
'ended' 'ended',
'videoHeight',
'videoWidth'
]); ]);
export default class Binding extends Node { export default class Binding extends Node {

@ -606,6 +606,16 @@ export default class Element extends Node {
message: `'${name}' binding can only be used with <audio> or <video>` message: `'${name}' binding can only be used with <audio> or <video>`
}); });
} }
} else if (
name === 'videoHeight' ||
name === 'videoWidth'
) {
if (this.name !== 'video') {
component.error(binding, {
code: `invalid-binding`,
message: `'${name}' binding can only be used with <video>`
});
}
} else if (dimensions.test(name)) { } else if (dimensions.test(name)) {
if (this.name === 'svg' && (name === 'offsetWidth' || name === 'offsetHeight')) { if (this.name === 'svg' && (name === 'offsetWidth' || name === 'offsetHeight')) {
component.error(binding, { component.error(binding, {

@ -112,6 +112,12 @@ const events = [
node.is_media_node() && node.is_media_node() &&
name === 'ended' name === 'ended'
}, },
{
event_names: ['resize'],
filter: (node: Element, name: string) =>
node.is_media_node() &&
(name === 'videoHeight' || name === 'videoWidth')
},
// details event // details event
{ {

@ -1,6 +1,7 @@
/* generated by Svelte vX.Y.Z */ /* generated by Svelte vX.Y.Z */
import { import {
SvelteComponent, SvelteComponent,
add_render_callback,
detach, detach,
element, element,
init, init,
@ -8,6 +9,7 @@ import {
listen, listen,
noop, noop,
raf, raf,
run_all,
safe_not_equal safe_not_equal
} from "svelte/internal"; } from "svelte/internal";
@ -31,7 +33,12 @@ function create_fragment(ctx) {
return { return {
c() { c() {
video = element("video"); video = element("video");
dispose = listen(video, "timeupdate", video_timeupdate_handler); if (ctx.videoHeight === void 0 || ctx.videoWidth === void 0) add_render_callback(() => ctx.video_resize_handler.call(video));
dispose = [
listen(video, "timeupdate", video_timeupdate_handler),
listen(video, "resize", ctx.video_resize_handler)
];
}, },
m(target, anchor) { m(target, anchor) {
insert(target, video, anchor); insert(target, video, anchor);
@ -47,30 +54,52 @@ function create_fragment(ctx) {
o: noop, o: noop,
d(detaching) { d(detaching) {
if (detaching) detach(video); if (detaching) detach(video);
dispose(); run_all(dispose);
} }
}; };
} }
function instance($$self, $$props, $$invalidate) { function instance($$self, $$props, $$invalidate) {
let { currentTime } = $$props; let { currentTime } = $$props;
let { videoHeight } = $$props;
let { videoWidth } = $$props;
function video_timeupdate_handler() { function video_timeupdate_handler() {
currentTime = this.currentTime; currentTime = this.currentTime;
$$invalidate("currentTime", currentTime); $$invalidate("currentTime", currentTime);
} }
function video_resize_handler() {
videoHeight = this.videoHeight;
videoWidth = this.videoWidth;
$$invalidate("videoHeight", videoHeight);
$$invalidate("videoWidth", videoWidth);
}
$$self.$set = $$props => { $$self.$set = $$props => {
if ("currentTime" in $$props) $$invalidate("currentTime", currentTime = $$props.currentTime); if ("currentTime" in $$props) $$invalidate("currentTime", currentTime = $$props.currentTime);
if ("videoHeight" in $$props) $$invalidate("videoHeight", videoHeight = $$props.videoHeight);
if ("videoWidth" in $$props) $$invalidate("videoWidth", videoWidth = $$props.videoWidth);
}; };
return { currentTime, video_timeupdate_handler }; return {
currentTime,
videoHeight,
videoWidth,
video_timeupdate_handler,
video_resize_handler
};
} }
class Component extends SvelteComponent { class Component extends SvelteComponent {
constructor(options) { constructor(options) {
super(); super();
init(this, options, instance, create_fragment, safe_not_equal, { currentTime: 0 });
init(this, options, instance, create_fragment, safe_not_equal, {
currentTime: 0,
videoHeight: 0,
videoWidth: 0
});
} }
} }

@ -1,5 +1,7 @@
<script> <script>
export let currentTime; export let currentTime;
export let videoHeight;
export let videoWidth;
</script> </script>
<video bind:currentTime/> <video bind:currentTime bind:videoHeight bind:videoWidth/>

Loading…
Cancel
Save