@fusion.dev/helix-core 0.56.0 → 0.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +646 -54
- package/dist/controllers/cue-controller/cue-controller.d.ts +85 -0
- package/dist/controllers/cue-controller/cue-controller.js +45 -0
- package/dist/controllers/fullscreen-controller/fullscreen-controller.d.ts +32 -0
- package/dist/controllers/fullscreen-controller/fullscreen-controller.js +28 -0
- package/dist/controllers/idle-controller/idle-controller.d.ts +35 -0
- package/dist/controllers/idle-controller/idle-controller.js +24 -0
- package/dist/controllers/media-session-controller/media-session-controller.d.ts +54 -0
- package/dist/controllers/media-session-controller/media-session-controller.js +49 -0
- package/dist/controllers/remote-playback-controller/remote-playback-controller.d.ts +34 -0
- package/dist/controllers/remote-playback-controller/remote-playback-controller.js +38 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +6 -1
- package/dist/utils/focusable-elements/focusable-elements.d.ts +9 -10
- package/dist/utils/media-copy/media-copy.d.ts +27 -0
- package/dist/utils/media-copy/media-copy.js +18 -0
- package/package.json +4 -4
- package/dist/controllers/focus-trap-controller/focus-trap-controller.d.ts +0 -26
- package/dist/controllers/focus-trap-controller/focus-trap-controller.js +0 -55
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
/** One caption track, named as the menu names it. */
|
|
3
|
+
export interface Caption {
|
|
4
|
+
label: string;
|
|
5
|
+
language: string;
|
|
6
|
+
}
|
|
7
|
+
/** A `<track>` as the consumer wrote it, reduced to what naming it needs. */
|
|
8
|
+
interface TrackCopy {
|
|
9
|
+
attrs: Record<string, string>;
|
|
10
|
+
tag: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The tracks a reader could choose between, in the order they were written.
|
|
14
|
+
*
|
|
15
|
+
* Filtered by kind, because `textTracks` also carries `chapters`, `metadata`
|
|
16
|
+
* and `descriptions`, and a menu offering "Chapters" as a subtitle language
|
|
17
|
+
* would be offering something that draws no words. Read off the media element
|
|
18
|
+
* rather than off the slot: a `<track>` added later is in one and not the
|
|
19
|
+
* other, and the element is the one that has resolved them.
|
|
20
|
+
*/
|
|
21
|
+
export declare const captionTracks: (media: HTMLMediaElement | null) => TextTrack[];
|
|
22
|
+
/**
|
|
23
|
+
* Shows one track and disables every other, or shows none at `-1`.
|
|
24
|
+
*
|
|
25
|
+
* Every other, rather than only the one that was on. Two tracks in `hidden`
|
|
26
|
+
* both fire `cuechange`, so the rendered cue becomes whichever fired last and
|
|
27
|
+
* a reader who switched language gets the two interleaved. Measured as two
|
|
28
|
+
* subtitles alternating line by line.
|
|
29
|
+
*
|
|
30
|
+
* `hidden`, never `showing`. Hidden is the mode where a track still fires
|
|
31
|
+
* `cuechange` and still fills `activeCues`, and the browser draws nothing,
|
|
32
|
+
* which is exactly what is wanted when something else is doing the drawing.
|
|
33
|
+
*/
|
|
34
|
+
export declare const showCaption: (tracks: readonly TextTrack[], index: number) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Whether a track the platform started showing is now ours to draw.
|
|
37
|
+
*
|
|
38
|
+
* A `<track default>` arrives `showing`, which is the browser drawing it.
|
|
39
|
+
* Moved to `hidden` so the cues keep coming and we draw them instead. What
|
|
40
|
+
* comes back is whether captions are on, which is not always "off": a button
|
|
41
|
+
* that began there reported the opposite of what was on screen.
|
|
42
|
+
*/
|
|
43
|
+
export declare const adoptTrack: (track: TextTrack) => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The caption tracks among the copies, before the render that draws them.
|
|
46
|
+
*
|
|
47
|
+
* By the platform's own reading of `kind`, which is what makes a `<track>` a
|
|
48
|
+
* caption at all: missing is `subtitles` and anything it does not know is
|
|
49
|
+
* `metadata`. Read from the video's tracks after the render instead, the count
|
|
50
|
+
* arrived a render late and asked for one more. Choosing one still goes
|
|
51
|
+
* through the video's tracks, which hold them in the same order.
|
|
52
|
+
*/
|
|
53
|
+
export declare const captionsAmong: (media: readonly TrackCopy[]) => Caption[];
|
|
54
|
+
/**
|
|
55
|
+
* The cue on screen now, as nodes, or nothing between cues.
|
|
56
|
+
*
|
|
57
|
+
* Nodes rather than a string, because `VTTCue.text` is the cue's *source*:
|
|
58
|
+
* WebVTT carries markup, and a caption file in the wild is full of it. `<v
|
|
59
|
+
* Hildy>` names who is speaking, `<b>` and `<i>` and `<u>` mark emphasis, and
|
|
60
|
+
* `<c.loud>` classes a line. Rendered as text every one of those arrives on
|
|
61
|
+
* screen as visible angle brackets.
|
|
62
|
+
*
|
|
63
|
+
* `getCueAsHTML` is the platform parsing its own format, so nothing here has
|
|
64
|
+
* to know the grammar and no cue text is ever treated as HTML: what comes
|
|
65
|
+
* back is a fragment the browser built, not a string anybody interpolated.
|
|
66
|
+
*/
|
|
67
|
+
export declare const activeCue: (track: TextTrack | undefined) => DocumentFragment | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Listens to one track's cues at a time, so the next one can take it off.
|
|
70
|
+
*
|
|
71
|
+
* Taken off whatever it was on before adding it here. `follow` runs from
|
|
72
|
+
* `loadedmetadata`, which fires again for every source a reader moves to, and
|
|
73
|
+
* a consumer adding a `<track>` later gets another. Added without removing, a
|
|
74
|
+
* playlist of six left six listeners on tracks that between them fire for
|
|
75
|
+
* every cue in the video.
|
|
76
|
+
*/
|
|
77
|
+
export declare class CueController implements ReactiveController {
|
|
78
|
+
private readonly listener;
|
|
79
|
+
private track;
|
|
80
|
+
constructor(host: ReactiveControllerHost, listener: () => void);
|
|
81
|
+
follow(track: TextTrack): void;
|
|
82
|
+
hostDisconnected(): void;
|
|
83
|
+
private stop;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const captionTracks = (media) => {
|
|
2
|
+
const tracks = media?.textTracks;
|
|
3
|
+
if (!tracks) {
|
|
4
|
+
return [];
|
|
5
|
+
}
|
|
6
|
+
return [...tracks].filter((one) => one.kind === 'subtitles' || one.kind === 'captions');
|
|
7
|
+
};
|
|
8
|
+
export const showCaption = (tracks, index) => {
|
|
9
|
+
tracks.forEach((track, at) => {
|
|
10
|
+
track.mode = at === index ? 'hidden' : 'disabled';
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export const adoptTrack = (track) => {
|
|
14
|
+
if (track.mode === 'showing') {
|
|
15
|
+
track.mode = 'hidden';
|
|
16
|
+
}
|
|
17
|
+
return track.mode === 'hidden';
|
|
18
|
+
};
|
|
19
|
+
export const captionsAmong = (media) => media
|
|
20
|
+
.filter((one) => one.tag === 'track' &&
|
|
21
|
+
(one.attrs.kind === undefined ||
|
|
22
|
+
['captions', 'subtitles'].includes(one.attrs.kind.toLowerCase())))
|
|
23
|
+
.map((one) => ({ label: one.attrs.label ?? '', language: one.attrs.srclang ?? '' }));
|
|
24
|
+
export const activeCue = (track) => {
|
|
25
|
+
const active = track?.activeCues?.[0];
|
|
26
|
+
return active instanceof VTTCue ? active.getCueAsHTML() : undefined;
|
|
27
|
+
};
|
|
28
|
+
export class CueController {
|
|
29
|
+
constructor(host, listener) {
|
|
30
|
+
this.listener = listener;
|
|
31
|
+
host.addController(this);
|
|
32
|
+
}
|
|
33
|
+
follow(track) {
|
|
34
|
+
this.stop();
|
|
35
|
+
this.track = track;
|
|
36
|
+
track.addEventListener('cuechange', this.listener);
|
|
37
|
+
}
|
|
38
|
+
hostDisconnected() {
|
|
39
|
+
this.stop();
|
|
40
|
+
}
|
|
41
|
+
stop() {
|
|
42
|
+
this.track?.removeEventListener('cuechange', this.listener);
|
|
43
|
+
this.track = undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Into fullscreen and back, and honest about where the element is.
|
|
4
|
+
*
|
|
5
|
+
* The state follows `fullscreenchange` rather than the request, so a refused
|
|
6
|
+
* request leaves a button that correctly reports "not fullscreen".
|
|
7
|
+
*
|
|
8
|
+
* The document, rather than the host, is what the event is read from: the
|
|
9
|
+
* platform fires it at the document whichever element went full, so a host that
|
|
10
|
+
* asked and was overruled by another one still hears about it.
|
|
11
|
+
*/
|
|
12
|
+
export declare class FullscreenController implements ReactiveController {
|
|
13
|
+
private readonly host;
|
|
14
|
+
private readonly report;
|
|
15
|
+
constructor(host: ReactiveControllerHost & HTMLElement, report: (full: boolean) => void);
|
|
16
|
+
/**
|
|
17
|
+
* Into fullscreen and back, and quiet about being refused.
|
|
18
|
+
*
|
|
19
|
+
* `requestFullscreen` rejects rather than returning false, and the two
|
|
20
|
+
* refusals a consumer will actually meet are a Permissions Policy that does
|
|
21
|
+
* not grant `fullscreen` to the frame the player is in, and a call without
|
|
22
|
+
* user activation. Both are `TypeError: Permissions check failed`, which is
|
|
23
|
+
* the same message for two different causes.
|
|
24
|
+
*
|
|
25
|
+
* Caught rather than `void`ed, or a refusal becomes an unhandled rejection
|
|
26
|
+
* naming neither the element nor the reason.
|
|
27
|
+
*/
|
|
28
|
+
toggle(): Promise<void>;
|
|
29
|
+
hostConnected(): void;
|
|
30
|
+
hostDisconnected(): void;
|
|
31
|
+
private readonly handleChange;
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class FullscreenController {
|
|
2
|
+
constructor(host, report) {
|
|
3
|
+
this.host = host;
|
|
4
|
+
this.report = report;
|
|
5
|
+
this.handleChange = () => {
|
|
6
|
+
this.report(document.fullscreenElement === this.host);
|
|
7
|
+
};
|
|
8
|
+
host.addController(this);
|
|
9
|
+
}
|
|
10
|
+
async toggle() {
|
|
11
|
+
try {
|
|
12
|
+
if (document.fullscreenElement === this.host) {
|
|
13
|
+
await document.exitFullscreen();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
await this.host.requestFullscreen();
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.warn(`<${this.host.localName}> could not enter fullscreen. If it is inside an iframe, that frame needs allow="fullscreen".`, error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
hostConnected() {
|
|
23
|
+
document.addEventListener('fullscreenchange', this.handleChange);
|
|
24
|
+
}
|
|
25
|
+
hostDisconnected() {
|
|
26
|
+
document.removeEventListener('fullscreenchange', this.handleChange);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* How long the reader has been still, which is what an overlay hides itself on.
|
|
4
|
+
*
|
|
5
|
+
* A wait rather than leaving with the pointer, or a reader moving across a
|
|
6
|
+
* surface to reach a control watches the control vanish under them. The wait is
|
|
7
|
+
* only ever about *idling*: whether anything else keeps the overlay up, a
|
|
8
|
+
* paused player or an open menu, is the host's decision, and this only says
|
|
9
|
+
* when the reader stopped.
|
|
10
|
+
*
|
|
11
|
+
* The delay is asked for on every restart rather than taken once, because it
|
|
12
|
+
* is a property the consumer can change while the video plays.
|
|
13
|
+
*/
|
|
14
|
+
export declare class IdleController implements ReactiveController {
|
|
15
|
+
private readonly delay;
|
|
16
|
+
private readonly report;
|
|
17
|
+
private timer;
|
|
18
|
+
constructor(host: ReactiveControllerHost, delay: () => number, report: (idle: boolean) => void);
|
|
19
|
+
/**
|
|
20
|
+
* Restarts the wait, on anything that counts as the reader being here.
|
|
21
|
+
*
|
|
22
|
+
* Pointer movement and focus both count, and both have to: a reader using the
|
|
23
|
+
* keyboard never moves a pointer, and a bar that only answered the mouse
|
|
24
|
+
* would leave them nothing to look at. Zero turns the wait off and the bar
|
|
25
|
+
* goes immediately; a large number keeps it up for as long as anyone is
|
|
26
|
+
* likely to look.
|
|
27
|
+
*/
|
|
28
|
+
readonly stir: () => void;
|
|
29
|
+
/**
|
|
30
|
+
* Leaving is the one case that does not wait: the reader has gone somewhere
|
|
31
|
+
* else, and there is nothing to reach for.
|
|
32
|
+
*/
|
|
33
|
+
readonly leave: () => void;
|
|
34
|
+
hostDisconnected(): void;
|
|
35
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class IdleController {
|
|
2
|
+
constructor(host, delay, report) {
|
|
3
|
+
this.delay = delay;
|
|
4
|
+
this.report = report;
|
|
5
|
+
this.stir = () => {
|
|
6
|
+
this.report(false);
|
|
7
|
+
clearTimeout(this.timer);
|
|
8
|
+
const delay = this.delay();
|
|
9
|
+
if (delay > 0) {
|
|
10
|
+
this.timer = setTimeout(() => {
|
|
11
|
+
this.report(true);
|
|
12
|
+
}, delay);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
this.leave = () => {
|
|
16
|
+
clearTimeout(this.timer);
|
|
17
|
+
this.report(true);
|
|
18
|
+
};
|
|
19
|
+
host.addController(this);
|
|
20
|
+
}
|
|
21
|
+
hostDisconnected() {
|
|
22
|
+
clearTimeout(this.timer);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* How far a skip control moves, in seconds.
|
|
4
|
+
*
|
|
5
|
+
* Ten, which is the number every player that has one uses, and the number the
|
|
6
|
+
* platform names in `seekbackward` and `seekforward` when it hands over a
|
|
7
|
+
* default. A different length here would be correct only on this player.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SKIP_SECONDS = 10;
|
|
10
|
+
/** What a headset's buttons do, handed over by the player that owns them. */
|
|
11
|
+
export interface SessionHandlers {
|
|
12
|
+
/**
|
|
13
|
+
* Asks for the next item, or `null` where the consumer has named nothing to
|
|
14
|
+
* skip to: the platform draws the key from whether a handler is set.
|
|
15
|
+
*/
|
|
16
|
+
next: (() => void) | null;
|
|
17
|
+
/** And the previous one, under the same rule. */
|
|
18
|
+
previous: (() => void) | null;
|
|
19
|
+
seek: (seconds: number) => void;
|
|
20
|
+
skipBy: (seconds: number) => void;
|
|
21
|
+
toggle: () => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Holds the page's media session for one player, and tells the platform what
|
|
25
|
+
* is playing.
|
|
26
|
+
*
|
|
27
|
+
* The handlers are what make a headset's play, pause and skip work at all.
|
|
28
|
+
* Without them a platform falls back to guessing which element was meant,
|
|
29
|
+
* which is right often enough to hide the fault and wrong exactly when there
|
|
30
|
+
* are two.
|
|
31
|
+
*/
|
|
32
|
+
export declare class MediaSessionController implements ReactiveController {
|
|
33
|
+
private readonly host;
|
|
34
|
+
constructor(host: ReactiveControllerHost & HTMLElement);
|
|
35
|
+
/**
|
|
36
|
+
* Takes the session.
|
|
37
|
+
*
|
|
38
|
+
* On play rather than on render, which is the ownership rule: a page with two
|
|
39
|
+
* players gives the session to whichever one the reader started, so a
|
|
40
|
+
* headset's buttons land on what they are listening to rather than on
|
|
41
|
+
* whichever came first in the markup.
|
|
42
|
+
*/
|
|
43
|
+
claim(metadata: {
|
|
44
|
+
artwork: string;
|
|
45
|
+
title: string;
|
|
46
|
+
}, handlers: SessionHandlers): void;
|
|
47
|
+
/** Tells the platform whether the owner is playing, and nothing if it is not the owner. */
|
|
48
|
+
report(playing: boolean): void;
|
|
49
|
+
/**
|
|
50
|
+
* The page's one media session goes back to nobody, but only if this
|
|
51
|
+
* element is the one holding it.
|
|
52
|
+
*/
|
|
53
|
+
hostDisconnected(): void;
|
|
54
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
let owner;
|
|
2
|
+
export const SKIP_SECONDS = 10;
|
|
3
|
+
export class MediaSessionController {
|
|
4
|
+
constructor(host) {
|
|
5
|
+
this.host = host;
|
|
6
|
+
host.addController(this);
|
|
7
|
+
}
|
|
8
|
+
claim(metadata, handlers) {
|
|
9
|
+
if (typeof navigator === 'undefined' || !navigator.mediaSession) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
owner = this.host;
|
|
13
|
+
const session = navigator.mediaSession;
|
|
14
|
+
session.metadata = new MediaMetadata({
|
|
15
|
+
artwork: metadata.artwork === '' ? [] : [{ src: metadata.artwork }],
|
|
16
|
+
title: metadata.title,
|
|
17
|
+
});
|
|
18
|
+
session.setActionHandler('play', handlers.toggle);
|
|
19
|
+
session.setActionHandler('pause', handlers.toggle);
|
|
20
|
+
session.setActionHandler('seekto', (details) => {
|
|
21
|
+
if (details.seekTime !== undefined && details.seekTime !== null) {
|
|
22
|
+
handlers.seek(details.seekTime);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
session.setActionHandler('seekbackward', (details) => {
|
|
26
|
+
handlers.skipBy(-(details.seekOffset ?? SKIP_SECONDS));
|
|
27
|
+
});
|
|
28
|
+
session.setActionHandler('seekforward', (details) => {
|
|
29
|
+
handlers.skipBy(details.seekOffset ?? SKIP_SECONDS);
|
|
30
|
+
});
|
|
31
|
+
session.setActionHandler('nexttrack', handlers.next);
|
|
32
|
+
session.setActionHandler('previoustrack', handlers.previous);
|
|
33
|
+
}
|
|
34
|
+
report(playing) {
|
|
35
|
+
if (owner === this.host && typeof navigator !== 'undefined' && navigator.mediaSession) {
|
|
36
|
+
navigator.mediaSession.playbackState = playing ? 'playing' : 'paused';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
hostDisconnected() {
|
|
40
|
+
if (owner !== this.host) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
owner = undefined;
|
|
44
|
+
if (typeof navigator !== 'undefined' && navigator.mediaSession) {
|
|
45
|
+
navigator.mediaSession.metadata = null;
|
|
46
|
+
navigator.mediaSession.playbackState = 'none';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
/** What the watch reports, as it learns it. */
|
|
3
|
+
export interface RemoteReport {
|
|
4
|
+
/** Whether anything on the network offers to play this. */
|
|
5
|
+
available: (available: boolean) => void;
|
|
6
|
+
/** Whether it is playing somewhere else right now. */
|
|
7
|
+
connected: (connected: boolean) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Watches for something to play the media on, and stops on the way out.
|
|
11
|
+
*
|
|
12
|
+
* The Remote Playback API is the standard one, and it is what Safari
|
|
13
|
+
* implements for AirPlay and Chrome for Cast: one call covers both, where the
|
|
14
|
+
* older `webkitShowPlaybackTargetPicker` covers only the first. Firefox has
|
|
15
|
+
* neither, and `remote` simply being absent is what turns the control off
|
|
16
|
+
* there.
|
|
17
|
+
*
|
|
18
|
+
* `watchAvailability` returns an id that has to be canceled, or the callback
|
|
19
|
+
* outlives the element that owns it: a callback holding a removed element is a
|
|
20
|
+
* leak with a `@state` write on the end.
|
|
21
|
+
*/
|
|
22
|
+
export declare class RemotePlaybackController implements ReactiveController {
|
|
23
|
+
private readonly report;
|
|
24
|
+
private media;
|
|
25
|
+
/** Cancels the availability watch, since it outlives a single render. */
|
|
26
|
+
private watch;
|
|
27
|
+
constructor(host: ReactiveControllerHost, report: RemoteReport);
|
|
28
|
+
/** Starts watching the media element, once there is one. */
|
|
29
|
+
attach(media: HTMLMediaElement): Promise<void>;
|
|
30
|
+
/** Opens the platform's own device picker. It has no list of its own. */
|
|
31
|
+
prompt(): Promise<void>;
|
|
32
|
+
hostDisconnected(): void;
|
|
33
|
+
private readonly handleState;
|
|
34
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class RemotePlaybackController {
|
|
2
|
+
constructor(host, report) {
|
|
3
|
+
this.report = report;
|
|
4
|
+
this.handleState = () => {
|
|
5
|
+
this.report.connected(this.media?.remote?.state === 'connected');
|
|
6
|
+
};
|
|
7
|
+
host.addController(this);
|
|
8
|
+
}
|
|
9
|
+
async attach(media) {
|
|
10
|
+
this.media = media;
|
|
11
|
+
media.remote?.addEventListener?.('connect', this.handleState);
|
|
12
|
+
media.remote?.addEventListener?.('disconnect', this.handleState);
|
|
13
|
+
const remote = media.remote;
|
|
14
|
+
if (!remote?.watchAvailability) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
this.watch = await remote.watchAvailability((available) => {
|
|
19
|
+
this.report.available(available);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async prompt() {
|
|
26
|
+
try {
|
|
27
|
+
await this.media?.remote?.prompt();
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
hostDisconnected() {
|
|
33
|
+
if (this.watch !== undefined) {
|
|
34
|
+
void this.media?.remote?.cancelWatchAvailability?.(this.watch);
|
|
35
|
+
this.watch = undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,14 +2,18 @@ export { AriaForwardController, type AriaForwardOptions, } from './controllers/a
|
|
|
2
2
|
export { ChartPointerController, type ChartPointerHost, } from './controllers/chart-pointer-controller/chart-pointer-controller.js';
|
|
3
3
|
export { CommandController, type CommandOptions, HelixFallbackCommandEvent, supportsInvokers, } from './controllers/command-controller/command-controller.js';
|
|
4
4
|
export { CopyController, type CopyOptions, } from './controllers/copy-controller/copy-controller.js';
|
|
5
|
+
export { activeCue, adoptTrack, type Caption, CueController, captionsAmong, captionTracks, showCaption, } from './controllers/cue-controller/cue-controller.js';
|
|
5
6
|
export { DisabledCascadeController, type DisabledCascadeOptions, } from './controllers/disabled-cascade-controller/disabled-cascade-controller.js';
|
|
6
7
|
export { DismissController, type DismissOptions, } from './controllers/dismiss-controller/dismiss-controller.js';
|
|
7
8
|
export { DrilldownController, type DrilldownOptions, } from './controllers/drilldown-controller/drilldown-controller.js';
|
|
8
9
|
export { FloatingController, type FloatingOptions, type Placement, type Side, } from './controllers/floating-controller/floating-controller.js';
|
|
9
|
-
export {
|
|
10
|
+
export { FullscreenController } from './controllers/fullscreen-controller/fullscreen-controller.js';
|
|
11
|
+
export { IdleController } from './controllers/idle-controller/idle-controller.js';
|
|
10
12
|
export { IndicatorController, type IndicatorOptions, } from './controllers/indicator-controller/indicator-controller.js';
|
|
11
13
|
export { KeyboardNavigationController, type KeyboardNavigationOptions, type NavigableItem, } from './controllers/keyboard-navigation-controller/keyboard-navigation-controller.js';
|
|
14
|
+
export { MediaSessionController, type SessionHandlers, SKIP_SECONDS, } from './controllers/media-session-controller/media-session-controller.js';
|
|
12
15
|
export { PopoverController, type PopoverOptions, } from './controllers/popover-controller/popover-controller.js';
|
|
16
|
+
export { RemotePlaybackController, type RemoteReport, } from './controllers/remote-playback-controller/remote-playback-controller.js';
|
|
13
17
|
export { SourceController, type SourceHost, } from './controllers/source-controller/source-controller.js';
|
|
14
18
|
export { type TokenColor, TokenColorController, } from './controllers/token-color-controller/token-color-controller.js';
|
|
15
19
|
export { type Rendered, VirtualizeController, type VirtualizeOptions, type Window as VirtualizeWindow, } from './controllers/virtualize-controller/virtualize-controller.js';
|
|
@@ -44,6 +48,7 @@ export { type DisableableItem, forgetDisabled, inheritDisabled, } from './utils/
|
|
|
44
48
|
export { inlineStep } from './utils/inline-step/inline-step.js';
|
|
45
49
|
export { type Curve, linePath, type Point } from './utils/line-path/line-path.js';
|
|
46
50
|
export { markRegion, type RegionOptions } from './utils/mark-region/mark-region.js';
|
|
51
|
+
export { copiesOf, type MediaCopy, sameCopies, } from './utils/media-copy/media-copy.js';
|
|
47
52
|
export { onUnlessFalse } from './utils/on-unless-false/on-unless-false.js';
|
|
48
53
|
export { type Row, type RowCell, readRows, readSeries, type Series, type SeriesPoint, } from './utils/read-series/read-series.js';
|
|
49
54
|
export { type Relative, relativeTime, } from './utils/relative-time/relative-time.js';
|
package/dist/index.js
CHANGED
|
@@ -2,14 +2,18 @@ export { AriaForwardController, } from './controllers/aria-forward-controller/ar
|
|
|
2
2
|
export { ChartPointerController, } from './controllers/chart-pointer-controller/chart-pointer-controller.js';
|
|
3
3
|
export { CommandController, HelixFallbackCommandEvent, supportsInvokers, } from './controllers/command-controller/command-controller.js';
|
|
4
4
|
export { CopyController, } from './controllers/copy-controller/copy-controller.js';
|
|
5
|
+
export { activeCue, adoptTrack, CueController, captionsAmong, captionTracks, showCaption, } from './controllers/cue-controller/cue-controller.js';
|
|
5
6
|
export { DisabledCascadeController, } from './controllers/disabled-cascade-controller/disabled-cascade-controller.js';
|
|
6
7
|
export { DismissController, } from './controllers/dismiss-controller/dismiss-controller.js';
|
|
7
8
|
export { DrilldownController, } from './controllers/drilldown-controller/drilldown-controller.js';
|
|
8
9
|
export { FloatingController, } from './controllers/floating-controller/floating-controller.js';
|
|
9
|
-
export {
|
|
10
|
+
export { FullscreenController } from './controllers/fullscreen-controller/fullscreen-controller.js';
|
|
11
|
+
export { IdleController } from './controllers/idle-controller/idle-controller.js';
|
|
10
12
|
export { IndicatorController, } from './controllers/indicator-controller/indicator-controller.js';
|
|
11
13
|
export { KeyboardNavigationController, } from './controllers/keyboard-navigation-controller/keyboard-navigation-controller.js';
|
|
14
|
+
export { MediaSessionController, SKIP_SECONDS, } from './controllers/media-session-controller/media-session-controller.js';
|
|
12
15
|
export { PopoverController, } from './controllers/popover-controller/popover-controller.js';
|
|
16
|
+
export { RemotePlaybackController, } from './controllers/remote-playback-controller/remote-playback-controller.js';
|
|
13
17
|
export { SourceController, } from './controllers/source-controller/source-controller.js';
|
|
14
18
|
export { TokenColorController, } from './controllers/token-color-controller/token-color-controller.js';
|
|
15
19
|
export { VirtualizeController, } from './controllers/virtualize-controller/virtualize-controller.js';
|
|
@@ -44,6 +48,7 @@ export { forgetDisabled, inheritDisabled, } from './utils/inherit-disabled/inher
|
|
|
44
48
|
export { inlineStep } from './utils/inline-step/inline-step.js';
|
|
45
49
|
export { linePath } from './utils/line-path/line-path.js';
|
|
46
50
|
export { markRegion } from './utils/mark-region/mark-region.js';
|
|
51
|
+
export { copiesOf, sameCopies, } from './utils/media-copy/media-copy.js';
|
|
47
52
|
export { onUnlessFalse } from './utils/on-unless-false/on-unless-false.js';
|
|
48
53
|
export { readRows, readSeries, } from './utils/read-series/read-series.js';
|
|
49
54
|
export { relativeTime, } from './utils/relative-time/relative-time.js';
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Everything inside `root` the reader can reach with Tab, in document order.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Roving tabindex, arrow-key navigation and "focus the first thing" all need
|
|
5
|
+
* this list, which is why it is a utility rather than part of anything that
|
|
6
|
+
* asks for it.
|
|
7
7
|
*
|
|
8
8
|
* Visibility is tested with `getClientRects()` rather than `offsetParent`,
|
|
9
|
-
* which is null for anything inside a `position: fixed` container
|
|
10
|
-
*
|
|
11
|
-
* being trapped.
|
|
9
|
+
* which is null for anything inside a `position: fixed` container, so the
|
|
10
|
+
* `offsetParent` test excluded every control on a raised surface.
|
|
12
11
|
*/
|
|
13
12
|
export declare const focusableElements: (root: HTMLElement) => HTMLElement[];
|
|
14
13
|
/**
|
|
@@ -23,13 +22,13 @@ export declare const deepActiveElement: () => Element | null;
|
|
|
23
22
|
*
|
|
24
23
|
* `Node.contains` walks `parentNode` and a shadow root's `parentNode` is null,
|
|
25
24
|
* so it answers false for anything inside a component. Paired with
|
|
26
|
-
* `deepActiveElement`, which returns exactly such a node,
|
|
27
|
-
*
|
|
25
|
+
* `deepActiveElement`, which returns exactly such a node, the pair is a hazard of
|
|
26
|
+
* its own: the two look like they belong together and one of them crosses.
|
|
28
27
|
*
|
|
29
28
|
* `contains(deepActiveElement())` is the shape to avoid: focus on a
|
|
30
29
|
* `helix-button` reports as the `<button>` in its shadow root, which is in no
|
|
31
|
-
* light-DOM container anywhere, so a
|
|
32
|
-
* as already outside
|
|
30
|
+
* light-DOM container anywhere, so a containment test written that way reads
|
|
31
|
+
* every reader as already outside.
|
|
33
32
|
*
|
|
34
33
|
* `host` is reached without naming `ShadowRoot`, which the server has no global
|
|
35
34
|
* for. This runs from a keydown handler and would never execute there, but a
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the consumer slotted, as the plain data a media element can be given.
|
|
3
|
+
*
|
|
4
|
+
* A media element runs resource selection over its own child nodes and a slot
|
|
5
|
+
* is one node, so anything wrapping `<video>` or `<audio>` in a shadow root has
|
|
6
|
+
* to copy rather than slot. The two questions that copying asks are answered
|
|
7
|
+
* here: which attributes come across, and whether a fresh read differs from the
|
|
8
|
+
* set already held. When to read, and what to do with the answer, stay with the
|
|
9
|
+
* element.
|
|
10
|
+
*
|
|
11
|
+
* A read of light DOM and nothing else: no media element, no playback state,
|
|
12
|
+
* nothing drawn, which is what makes it a utility rather than a controller.
|
|
13
|
+
*/
|
|
14
|
+
/** A `<source>` or `<track>` as the consumer wrote it, reduced to what the copy carries. */
|
|
15
|
+
export interface MediaCopy {
|
|
16
|
+
attrs: Record<string, string>;
|
|
17
|
+
tag: 'source' | 'track';
|
|
18
|
+
}
|
|
19
|
+
/** The copies to make of what the default slot is given. */
|
|
20
|
+
export declare const copiesOf: (elements: readonly Element[]) => MediaCopy[];
|
|
21
|
+
/**
|
|
22
|
+
* Whether two reads describe the same media.
|
|
23
|
+
*
|
|
24
|
+
* The same set again is not a change. A video reloads for every new list, and
|
|
25
|
+
* the first `slotchange` reports the children the element has already read.
|
|
26
|
+
*/
|
|
27
|
+
export declare const sameCopies: (one: readonly MediaCopy[], two: readonly MediaCopy[]) => boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const CARRIED = {
|
|
2
|
+
source: ['media', 'sizes', 'src', 'srcset', 'type'],
|
|
3
|
+
track: ['default', 'kind', 'label', 'src', 'srclang'],
|
|
4
|
+
};
|
|
5
|
+
export const copiesOf = (elements) => elements
|
|
6
|
+
.filter((node) => node instanceof HTMLSourceElement || node instanceof HTMLTrackElement)
|
|
7
|
+
.map((node) => {
|
|
8
|
+
const tag = node instanceof HTMLTrackElement ? 'track' : 'source';
|
|
9
|
+
const attrs = {};
|
|
10
|
+
for (const name of CARRIED[tag]) {
|
|
11
|
+
const value = node.getAttribute(name);
|
|
12
|
+
if (value !== null) {
|
|
13
|
+
attrs[name] = value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return { attrs, tag };
|
|
17
|
+
});
|
|
18
|
+
export const sameCopies = (one, two) => JSON.stringify(one) === JSON.stringify(two);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fusion.dev/helix-core",
|
|
3
3
|
"description": "Helix element primitives: base classes, mixins, decorators, utilities.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.57.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ross Sheppard <ross.sheppard@fusion.dev>",
|
|
7
7
|
"repository": {
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"bugs": "https://github.com/project-fusion/fusion/issues",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@floating-ui/dom": "^1.8.0",
|
|
37
|
-
"@fusion.dev/helix-icons": "0.
|
|
37
|
+
"@fusion.dev/helix-icons": "0.57.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@custom-elements-manifest/analyzer": "^0.11.0",
|
|
41
|
-
"@fusion.dev/helix-cem": "0.
|
|
42
|
-
"@fusion.dev/helix-testing": "0.
|
|
41
|
+
"@fusion.dev/helix-cem": "0.57.0",
|
|
42
|
+
"@fusion.dev/helix-testing": "0.57.0",
|
|
43
43
|
"lit": "^3.2.1"
|
|
44
44
|
},
|
|
45
45
|
"homepage": "https://fusion.dev",
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
-
/**
|
|
3
|
-
* Keeps Tab inside a container while it is open, and gives focus back after.
|
|
4
|
-
*
|
|
5
|
-
* A dialog that does not trap focus is one a keyboard user tabs straight out
|
|
6
|
-
* of, into a page they cannot see and cannot get back from. Restoring focus on
|
|
7
|
-
* release matters just as much: without it, closing a drawer drops the reader
|
|
8
|
-
* at the top of the document.
|
|
9
|
-
*
|
|
10
|
-
* Finding the focusable elements is `focusableElements`, which is a utility
|
|
11
|
-
* rather than part of this, because that half is what roving tabindex and
|
|
12
|
-
* arrow-key navigation need and neither of them traps anything.
|
|
13
|
-
*/
|
|
14
|
-
export declare class FocusTrapController implements ReactiveController {
|
|
15
|
-
private container;
|
|
16
|
-
/** The frame waiting to take focus, so a release can call it off. */
|
|
17
|
-
private frame;
|
|
18
|
-
private previous;
|
|
19
|
-
constructor(host: ReactiveControllerHost);
|
|
20
|
-
private readonly handleKeydown;
|
|
21
|
-
/** Starts trapping, remembering where focus came from. */
|
|
22
|
-
activate(container: HTMLElement): void;
|
|
23
|
-
/** Stops trapping and returns focus to wherever it was. */
|
|
24
|
-
deactivate(): void;
|
|
25
|
-
hostDisconnected(): void;
|
|
26
|
-
}
|