Skip to content

Commit a37ee81

Browse files
committed
added the muted attribute to audio and video tags
1 parent 593de0e commit a37ee81

File tree

9 files changed

+28
-15
lines changed

9 files changed

+28
-15
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/compile/nodes/Element.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ export default class Element extends Node {
582582
name === 'seekable' ||
583583
name === 'played' ||
584584
name === 'volume' ||
585+
name === 'muted' ||
585586
name === 'playbackRate'
586587
) {
587588
if (this.name !== 'audio' && this.name !== 'video') {
@@ -610,7 +611,7 @@ export default class Element extends Node {
610611
} else if (
611612
name === 'text' ||
612613
name === 'html'
613-
){
614+
) {
614615
const contenteditable = this.attributes.find(
615616
(attribute: Attribute) => attribute.name === 'contenteditable'
616617
);
@@ -626,7 +627,7 @@ export default class Element extends Node {
626627
message: `'contenteditable' attribute cannot be dynamic if element uses two-way binding`
627628
});
628629
}
629-
} else if (name !== 'this') {
630+
} else if (name !== 'this') {
630631
component.error(binding, {
631632
code: `invalid-binding`,
632633
message: `'${binding.name}' is not a valid binding`

src/compiler/compile/render-dom/wrappers/Element/Binding.ts

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ export default class BindingWrapper {
138138
case 'volume':
139139
update_conditions.push(`!isNaN(${this.snippet})`);
140140
break;
141+
142+
case 'muted':
143+
update_dom = `${parent.var}.${this.node.name} = !!${this.snippet};`;
144+
break;
141145

142146
case 'paused':
143147
{

src/compiler/compile/render-dom/wrappers/Element/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const events = [
8686
event_names: ['volumechange'],
8787
filter: (node: Element, name: string) =>
8888
node.is_media_node() &&
89-
name === 'volume'
89+
(name === 'volume' || name === 'muted')
9090
},
9191
{
9292
event_names: ['ratechange'],

src/compiler/compile/render-ssr/handlers/Element.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ export default function(node: Element, renderer: Renderer, options: RenderOption
151151
if (name === 'group') {
152152
// TODO server-render group bindings
153153
} else if (contenteditable && (name === 'text' || name === 'html')) {
154-
const snippet = snip(expression)
154+
const snippet = snip(expression);
155155
if (name == 'text') {
156-
node_contents = '${@escape(' + snippet + ')}'
156+
node_contents = '${@escape(' + snippet + ')}';
157157
} else {
158158
// Do not escape HTML content
159-
node_contents = '${' + snippet + '}'
159+
node_contents = '${' + snippet + '}';
160160
}
161161
} else if (binding.name === 'value' && node.name === 'textarea') {
162162
const snippet = snip(expression);

src/runtime/internal/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function once(fn) {
8787
if (ran) return;
8888
ran = true;
8989
fn.call(this, ...args);
90-
}
90+
};
9191
}
9292

9393
const is_client = typeof window !== 'undefined';

test/js/samples/media-bindings/expected.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ function create_fragment(ctx) {
4949

5050
audio.volume = ctx.volume;
5151

52+
audio.muted = !!ctx.muted;
53+
5254
audio.playbackRate = ctx.playbackRate;
5355
},
5456

5557
p(changed, ctx) {
5658
if (!audio_updating && changed.currentTime && !isNaN(ctx.currentTime)) audio.currentTime = ctx.currentTime;
5759
if (changed.paused && audio_is_paused !== (audio_is_paused = ctx.paused)) audio[audio_is_paused ? "pause" : "play"]();
5860
if (changed.volume && !isNaN(ctx.volume)) audio.volume = ctx.volume;
61+
if (changed.muted) audio.muted = !!ctx.muted;
5962
if (changed.playbackRate && !isNaN(ctx.playbackRate)) audio.playbackRate = ctx.playbackRate;
6063
audio_updating = false;
6164
},
@@ -74,7 +77,7 @@ function create_fragment(ctx) {
7477
}
7578

7679
function instance($$self, $$props, $$invalidate) {
77-
let { buffered, seekable, played, currentTime, duration, paused, volume, playbackRate } = $$props;
80+
let { buffered, seekable, played, currentTime, duration, paused, volume, muted, playbackRate } = $$props;
7881

7982
function audio_timeupdate_handler() {
8083
played = time_ranges_to_array(this.played);
@@ -107,7 +110,9 @@ function instance($$self, $$props, $$invalidate) {
107110

108111
function audio_volumechange_handler() {
109112
volume = this.volume;
113+
muted = this.muted;
110114
$$invalidate('volume', volume);
115+
$$invalidate('muted', muted);
111116
}
112117

113118
function audio_ratechange_handler() {
@@ -123,6 +128,7 @@ function instance($$self, $$props, $$invalidate) {
123128
if ('duration' in $$props) $$invalidate('duration', duration = $$props.duration);
124129
if ('paused' in $$props) $$invalidate('paused', paused = $$props.paused);
125130
if ('volume' in $$props) $$invalidate('volume', volume = $$props.volume);
131+
if ('muted' in $$props) $$invalidate('muted', muted = $$props.muted);
126132
if ('playbackRate' in $$props) $$invalidate('playbackRate', playbackRate = $$props.playbackRate);
127133
};
128134

@@ -134,6 +140,7 @@ function instance($$self, $$props, $$invalidate) {
134140
duration,
135141
paused,
136142
volume,
143+
muted,
137144
playbackRate,
138145
audio_timeupdate_handler,
139146
audio_durationchange_handler,
@@ -148,8 +155,8 @@ function instance($$self, $$props, $$invalidate) {
148155
class Component extends SvelteComponent {
149156
constructor(options) {
150157
super();
151-
init(this, options, instance, create_fragment, safe_not_equal, ["buffered", "seekable", "played", "currentTime", "duration", "paused", "volume", "playbackRate"]);
158+
init(this, options, instance, create_fragment, safe_not_equal, ["buffered", "seekable", "played", "currentTime", "duration", "paused", "volume", "muted", "playbackRate"]);
152159
}
153160
}
154161

155-
export default Component;
162+
export default Component;

test/js/samples/media-bindings/input.svelte

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
export let duration;
77
export let paused;
88
export let volume;
9+
export let muted;
910
export let playbackRate;
1011
</script>
1112

12-
<audio bind:buffered bind:seekable bind:played bind:currentTime bind:duration bind:paused bind:volume bind:playbackRate/>
13+
<audio bind:buffered bind:seekable bind:played bind:currentTime bind:duration bind:paused bind:volume bind:muted bind:playbackRate/>

test/runtime/samples/contenteditable-html/_config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ export default {
1919

2020
el.innerHTML = 'every<span>body</span>';
2121

22-
// No updates to data yet
22+
// No updates to data yet
2323
assert.htmlEqual(target.innerHTML, `
2424
<editor>every<span>body</span></editor>
2525
<p>hello <b>world</b></p>
2626
`);
2727

28-
// Handle user input
29-
const event = new window.Event('input');
28+
// Handle user input
29+
const event = new window.Event('input');
3030
await el.dispatchEvent(event);
3131
assert.htmlEqual(target.innerHTML, `
3232
<editor>every<span>body</span></editor>

0 commit comments

Comments
 (0)