Home / File/ media.js — svelte Source File

media.js — svelte Source File

Architecture documentation for media.js, a javascript file in the svelte codebase. 6 imports, 0 dependents.

File javascript ClientRuntime Hydration 6 imports 12 functions

Entity Profile

Dependency Diagram

graph LR
  1fdae683_fcfe_7f32_daab_6a4edc3c6b85["media.js"]
  1ae6fa4e_16ee_acdf_5e28_17eb0819fddb["effects.js"]
  1fdae683_fcfe_7f32_daab_6a4edc3c6b85 --> 1ae6fa4e_16ee_acdf_5e28_17eb0819fddb
  7494b934_a3b8_689e_91b6_8435e26461c5["render_effect"]
  1fdae683_fcfe_7f32_daab_6a4edc3c6b85 --> 7494b934_a3b8_689e_91b6_8435e26461c5
  a985ae40_8ef8_7ef2_adad_116fbf97e70c["effect"]
  1fdae683_fcfe_7f32_daab_6a4edc3c6b85 --> a985ae40_8ef8_7ef2_adad_116fbf97e70c
  20340432_01a2_6741_abf4_60ccab51cdb3["teardown"]
  1fdae683_fcfe_7f32_daab_6a4edc3c6b85 --> 20340432_01a2_6741_abf4_60ccab51cdb3
  af7441d2_339a_2db1_88df_90dba2875c10["shared.js"]
  1fdae683_fcfe_7f32_daab_6a4edc3c6b85 --> af7441d2_339a_2db1_88df_90dba2875c10
  da178604_a1e6_1104_9d60_daf043f014c9["listen"]
  1fdae683_fcfe_7f32_daab_6a4edc3c6b85 --> da178604_a1e6_1104_9d60_daf043f014c9
  style 1fdae683_fcfe_7f32_daab_6a4edc3c6b85 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { render_effect, effect, teardown } from '../../../reactivity/effects.js';
import { listen } from './shared.js';

/** @param {TimeRanges} ranges */
function time_ranges_to_array(ranges) {
	var array = [];

	for (var i = 0; i < ranges.length; i += 1) {
		array.push({ start: ranges.start(i), end: ranges.end(i) });
	}

	return array;
}

/**
 * @param {HTMLVideoElement | HTMLAudioElement} media
 * @param {() => number | undefined} get
 * @param {(value: number) => void} set
 * @returns {void}
 */
export function bind_current_time(media, get, set = get) {
	/** @type {number} */
	var raf_id;
	/** @type {number} */
	var value;

	// Ideally, listening to timeupdate would be enough, but it fires too infrequently for the currentTime
	// binding, which is why we use a raf loop, too. We additionally still listen to timeupdate because
	// the user could be scrubbing through the video using the native controls when the media is paused.
	var callback = () => {
		cancelAnimationFrame(raf_id);

		if (!media.paused) {
			raf_id = requestAnimationFrame(callback);
		}

		var next_value = media.currentTime;
		if (value !== next_value) {
			set((value = next_value));
		}
	};

	raf_id = requestAnimationFrame(callback);
	media.addEventListener('timeupdate', callback);

	render_effect(() => {
		var next_value = Number(get());

		if (value !== next_value && !isNaN(/** @type {any} */ (next_value))) {
			media.currentTime = value = next_value;
		}
	});

	teardown(() => {
		cancelAnimationFrame(raf_id);
		media.removeEventListener('timeupdate', callback);
	});
}

/**
// ... (174 more lines)

Domain

Subdomains

Frequently Asked Questions

What does media.js do?
media.js is a source file in the svelte codebase, written in javascript. It belongs to the ClientRuntime domain, Hydration subdomain.
What functions are defined in media.js?
media.js defines 12 function(s): bind_buffered, bind_current_time, bind_ended, bind_muted, bind_paused, bind_playback_rate, bind_played, bind_ready_state, bind_seekable, bind_seeking, and 2 more.
What does media.js depend on?
media.js imports 6 module(s): effect, effects.js, listen, render_effect, shared.js, teardown.
Where is media.js in the architecture?
media.js is located at packages/svelte/src/internal/client/dom/elements/bindings/media.js (domain: ClientRuntime, subdomain: Hydration, directory: packages/svelte/src/internal/client/dom/elements/bindings).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free