Skip to content

Commit 41827f7

Browse files
authored
svelte media bindings (#502)
* svelte media bindings * add both lowercase and camelCase variant * remove lowercase variant when it can't be HTML Attribute #500, #494
1 parent 638b295 commit 41827f7

File tree

2 files changed

+73
-5
lines changed

2 files changed

+73
-5
lines changed

packages/language-server/src/plugins/html/dataProvider.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,42 @@ const mediaAttributes: IAttributeData[] = [
195195
name: 'bind:played',
196196
description: 'An array of {start, end} objects. (readonly)',
197197
},
198+
{
199+
name: 'bind:seeking',
200+
description: 'boolean. (readonly)'
201+
},
202+
{
203+
name: 'bind:ended',
204+
description: 'boolean. (readonly)'
205+
},
198206
{
199207
name: 'bind:currentTime',
200208
description: 'The current point in the video, in seconds.',
201209
},
210+
{
211+
name: 'bind:playbackRate',
212+
description: `how fast or slow to play the video, where 1 is 'normal'`
213+
},
202214
{
203215
name: 'bind:paused',
204216
},
205217
{
206218
name: 'bind:volume',
207219
description: 'A value between 0 and 1',
208220
},
221+
{
222+
name: 'bind:muted',
223+
},
224+
];
225+
const videoAttributes: IAttributeData[] = [
226+
{
227+
name: 'bind:videoWidth',
228+
description: 'readonly'
229+
},
230+
{
231+
name: 'bind:videoHeight',
232+
description: 'readonly'
233+
}
209234
];
210235

211236
const addAttributes: Record<string, IAttributeData[]> = {
@@ -215,7 +240,7 @@ const addAttributes: Record<string, IAttributeData[]> = {
215240
{ name: 'bind:group', description: 'Available for type="radio" and type="checkbox"' },
216241
],
217242
textarea: [{ name: 'bind:value' }],
218-
video: [...mediaAttributes],
243+
video: [...mediaAttributes, ...videoAttributes],
219244
audio: [...mediaAttributes],
220245
};
221246

packages/svelte2tsx/svelte-jsx.d.ts

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,17 @@
248248
content?: string;
249249
contenteditable?: "true" | "false" | boolean;
250250

251+
// Doesn't work when used as HTML attribute
251252
/**
252253
* Elements with the contenteditable attribute support innerHTML and textContent bindings.
253254
*/
254-
innerhtml?: string;
255+
innerHTML?: string;
256+
// Doesn't work when used as HTML attribute
255257
/**
256258
* Elements with the contenteditable attribute support innerHTML and textContent bindings.
257259
*/
258-
textcontent?: string;
260+
261+
textContent?: string;
259262

260263
contextmenu?: string;
261264
controls?: boolean;
@@ -358,6 +361,9 @@
358361
type?: string;
359362
usemap?: string;
360363
value?: string | string[] | number;
364+
/**
365+
* a value between 0 and 1
366+
*/
361367
volume?: number;
362368
width?: number | string;
363369
wmode?: string;
@@ -713,9 +719,46 @@
713719
}
714720

715721
interface SapperAnchorProps {
722+
// transformed from sapper:noscroll so it should be camel case
716723
sapperNoscroll?: true;
717724
}
718725

726+
interface SvelteMediaTimeRange {
727+
start: number;
728+
end: number;
729+
}
730+
731+
interface SvelteMediaProps {
732+
readonly duration?: number;
733+
readonly buffered?: SvelteMediaTimeRange[];
734+
readonly played?: SvelteMediaTimeRange[];
735+
readonly seekable?: SvelteMediaTimeRange[];
736+
readonly seeking?: boolean;
737+
readonly ended?: boolean;
738+
739+
/**
740+
* the current playback time in the video, in seconds
741+
*/
742+
currentTime?: number;
743+
/**
744+
* the current playback time in the video, in seconds
745+
*/
746+
currenttime?: number;
747+
// Doesn't work when used as HTML Attribute
748+
/**
749+
* how fast or slow to play the video, where 1 is 'normal'
750+
*/
751+
playbackRate?: number;
752+
753+
paused?: boolean;
754+
}
755+
756+
interface SvelteVideoProps extends SvelteMediaProps {
757+
// Binding only, don't need lowercase variant
758+
readonly videoWidth?: number;
759+
readonly videoHeight?: number;
760+
}
761+
719762
interface IntrinsicElements {
720763
// HTML
721764
a: HTMLProps<HTMLAnchorElement> & SapperAnchorProps;
@@ -724,7 +767,7 @@
724767
area: HTMLProps<HTMLAreaElement>;
725768
article: HTMLProps<HTMLElement>;
726769
aside: HTMLProps<HTMLElement>;
727-
audio: HTMLProps<HTMLAudioElement>;
770+
audio: HTMLProps<HTMLAudioElement> & SvelteMediaProps;
728771
b: HTMLProps<HTMLElement>;
729772
base: HTMLProps<HTMLBaseElement>;
730773
bdi: HTMLProps<HTMLElement>;
@@ -830,7 +873,7 @@
830873
u: HTMLProps<HTMLElement>;
831874
ul: HTMLProps<HTMLUListElement>;
832875
var: HTMLProps<HTMLElement>;
833-
video: HTMLProps<HTMLVideoElement>;
876+
video: HTMLProps<HTMLVideoElement> & SvelteVideoProps;
834877
wbr: HTMLProps<HTMLElement>;
835878

836879
svg: SVGProps<SVGSVGElement>;

0 commit comments

Comments
 (0)