-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3927 from MattiasBuelens/video-bindings
Add bindings for HTMLVideoElement.videoWidth and videoHeight
- Loading branch information
Showing
6 changed files
with
155 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* generated by Svelte vX.Y.Z */ | ||
import { | ||
SvelteComponent, | ||
add_render_callback, | ||
add_resize_listener, | ||
detach, | ||
element, | ||
init, | ||
insert, | ||
listen, | ||
noop, | ||
raf, | ||
run_all, | ||
safe_not_equal | ||
} from "svelte/internal"; | ||
|
||
function create_fragment(ctx) { | ||
let video; | ||
let video_updating = false; | ||
let video_resize_listener; | ||
let video_animationframe; | ||
let dispose; | ||
|
||
function video_timeupdate_handler() { | ||
cancelAnimationFrame(video_animationframe); | ||
|
||
if (!video.paused) { | ||
video_animationframe = raf(video_timeupdate_handler); | ||
video_updating = true; | ||
} | ||
|
||
ctx.video_timeupdate_handler.call(video); | ||
} | ||
|
||
return { | ||
c() { | ||
video = element("video"); | ||
add_render_callback(() => ctx.video_elementresize_handler.call(video)); | ||
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) { | ||
insert(target, video, anchor); | ||
video_resize_listener = add_resize_listener(video, ctx.video_elementresize_handler.bind(video)); | ||
}, | ||
p(changed, ctx) { | ||
if (!video_updating && changed.currentTime && !isNaN(ctx.currentTime)) { | ||
video.currentTime = ctx.currentTime; | ||
} | ||
|
||
video_updating = false; | ||
}, | ||
i: noop, | ||
o: noop, | ||
d(detaching) { | ||
if (detaching) detach(video); | ||
video_resize_listener.cancel(); | ||
run_all(dispose); | ||
} | ||
}; | ||
} | ||
|
||
function instance($$self, $$props, $$invalidate) { | ||
let { currentTime } = $$props; | ||
let { videoHeight } = $$props; | ||
let { videoWidth } = $$props; | ||
let { offsetWidth } = $$props; | ||
|
||
function video_elementresize_handler() { | ||
offsetWidth = this.offsetWidth; | ||
$$invalidate("offsetWidth", offsetWidth); | ||
} | ||
|
||
function video_timeupdate_handler() { | ||
currentTime = this.currentTime; | ||
$$invalidate("currentTime", currentTime); | ||
} | ||
|
||
function video_resize_handler() { | ||
videoHeight = this.videoHeight; | ||
videoWidth = this.videoWidth; | ||
$$invalidate("videoHeight", videoHeight); | ||
$$invalidate("videoWidth", videoWidth); | ||
} | ||
|
||
$$self.$set = $$props => { | ||
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); | ||
if ("offsetWidth" in $$props) $$invalidate("offsetWidth", offsetWidth = $$props.offsetWidth); | ||
}; | ||
|
||
return { | ||
currentTime, | ||
videoHeight, | ||
videoWidth, | ||
offsetWidth, | ||
video_elementresize_handler, | ||
video_timeupdate_handler, | ||
video_resize_handler | ||
}; | ||
} | ||
|
||
class Component extends SvelteComponent { | ||
constructor(options) { | ||
super(); | ||
|
||
init(this, options, instance, create_fragment, safe_not_equal, { | ||
currentTime: 0, | ||
videoHeight: 0, | ||
videoWidth: 0, | ||
offsetWidth: 0 | ||
}); | ||
} | ||
} | ||
|
||
export default Component; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script> | ||
export let currentTime; | ||
export let videoHeight; | ||
export let videoWidth; | ||
export let offsetWidth; | ||
</script> | ||
|
||
<video bind:currentTime bind:videoHeight bind:videoWidth bind:offsetWidth/> |