@nrk/player-elements
Advanced tools
| import type { Subtitles } from '@nrk/player-core/'; | ||
| export declare function isDefault(subtitles: Subtitles): boolean; | ||
| export declare function isCaptions(subtitles: Subtitles): boolean; | ||
| export declare function isAutoSelectable(subtitles: Subtitles): boolean; | ||
| export declare function isForced(subtitles: Subtitles): boolean; | ||
| export declare function tidyUpSubtitleRoles(subtitles: Subtitles[], contentType: string, isLive: boolean): Subtitles[]; |
| import { getLogger } from "@nrk/web-logger"; | ||
| import { DASH_CONTENT_TYPE, HLS_CONTENT_TYPE } from "../player/player-types"; | ||
| const DASH_ROLE_CAPTIONS = "caption"; | ||
| const DASH_ROLE_MAIN = "main"; | ||
| const DASH_ROLE_SUBTITLES = "subtitle"; | ||
| const HLS_ROLE_CAPTIONS = "public.accessibility.describes-music-and-sound"; | ||
| const HLS_ROLE_TRANSCRIBES = "public.accessibility.transcribes-spoken-dialog"; | ||
| const NRK_ROLE_CAPTIONS = "describes"; | ||
| const NRK_ROLE_DEFAULT = "default"; | ||
| const NRK_ROLE_TRANSCRIBES = "transcribes"; | ||
| const NRK_ROLE_TRANSLATES = "translates"; | ||
| const logger = getLogger("SubtitlesRoles"); | ||
| function isDefault(subtitles) { | ||
| if (subtitles.roles === void 0) { | ||
| return false; | ||
| } | ||
| return subtitles.roles.some((role) => role === "default" || role === "main"); | ||
| } | ||
| function isCaptions(subtitles) { | ||
| if (subtitles.roles?.includes(HLS_ROLE_CAPTIONS)) { | ||
| return true; | ||
| } | ||
| if (subtitles.roles !== void 0 && subtitles.roles.some((role) => role === "caption" || role === "captions")) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| function isAutoSelectable(subtitles) { | ||
| if (subtitles.roles === void 0) { | ||
| return false; | ||
| } | ||
| return subtitles.roles.some((role) => role === "autoselect"); | ||
| } | ||
| function isForced(subtitles) { | ||
| if (subtitles.roles === void 0) { | ||
| return false; | ||
| } | ||
| return subtitles.roles.some((role) => role === "forced" || role === "forced-subtitle"); | ||
| } | ||
| function tidyUpSubtitleRoles(subtitles, contentType, isLive) { | ||
| const isHLS = contentType.toLowerCase() === HLS_CONTENT_TYPE; | ||
| const isDASH = contentType.toLowerCase() === DASH_CONTENT_TYPE; | ||
| let isDefaultSet = false; | ||
| for (const subtitle of subtitles) { | ||
| if (subtitle.roles?.includes(DASH_ROLE_CAPTIONS) || subtitle.roles?.includes(HLS_ROLE_CAPTIONS)) { | ||
| processCaptionsTrack(subtitle, { isDefaultSet }); | ||
| } else if (isHLS && subtitle.roles?.includes(HLS_ROLE_TRANSCRIBES) || isDASH && subtitle.roles?.includes(DASH_ROLE_SUBTITLES)) { | ||
| processTranscribesTrack(subtitle, { isDefaultSet }); | ||
| } else { | ||
| processTranslatesTrack(subtitle, { isDASH, isDefaultSet }); | ||
| } | ||
| if (!isDefaultSet && subtitle.roles?.includes(NRK_ROLE_DEFAULT)) { | ||
| isDefaultSet = true; | ||
| } | ||
| } | ||
| if (!isDefaultSet) { | ||
| chooseDefaultTrack(subtitles, { isLive }); | ||
| } | ||
| return subtitles; | ||
| } | ||
| function processCaptionsTrack(subtitle, context) { | ||
| const rolesBefore = Array.from(subtitle.roles ?? []); | ||
| const roles = new Set(subtitle.roles ?? []); | ||
| roles.delete(DASH_ROLE_SUBTITLES); | ||
| roles.delete(HLS_ROLE_TRANSCRIBES); | ||
| roles.add(NRK_ROLE_CAPTIONS); | ||
| roles.add(HLS_ROLE_CAPTIONS); | ||
| roles.add(DASH_ROLE_CAPTIONS); | ||
| if (roles.has(DASH_ROLE_MAIN)) { | ||
| if (!context.isDefaultSet) { | ||
| roles.add(NRK_ROLE_DEFAULT); | ||
| } | ||
| roles.delete(DASH_ROLE_MAIN); | ||
| } | ||
| subtitle.roles = Array.from(roles); | ||
| subtitle.roles.sort(); | ||
| logger.log( | ||
| `Track "${subtitle.label}" [describes]: Changed roles from "${rolesBefore.join("|")}" to "${subtitle.roles.join("|")}".` | ||
| ); | ||
| } | ||
| function processTranscribesTrack(subtitle, context) { | ||
| const rolesBefore = Array.from(subtitle.roles ?? []); | ||
| const roles = new Set(subtitle.roles ?? []); | ||
| roles.add(NRK_ROLE_TRANSCRIBES); | ||
| roles.add(HLS_ROLE_TRANSCRIBES); | ||
| roles.add(DASH_ROLE_SUBTITLES); | ||
| if (roles.has(DASH_ROLE_MAIN)) { | ||
| if (!context.isDefaultSet) { | ||
| roles.add(NRK_ROLE_DEFAULT); | ||
| } | ||
| roles.delete(DASH_ROLE_MAIN); | ||
| } | ||
| subtitle.roles = Array.from(roles); | ||
| subtitle.roles.sort(); | ||
| logger.log( | ||
| `Track "${subtitle.label}" [transcribes]: Changed roles from "${rolesBefore.join("|")}" to "${subtitle.roles.join("|")}".` | ||
| ); | ||
| } | ||
| function processTranslatesTrack(subtitle, context) { | ||
| const rolesBefore = Array.from(subtitle.roles ?? []); | ||
| const roles = new Set(subtitle.roles ?? []); | ||
| roles.add(NRK_ROLE_TRANSLATES); | ||
| roles.delete(DASH_ROLE_SUBTITLES); | ||
| if (!context.isDASH) { | ||
| if (roles.has(DASH_ROLE_MAIN) && !context.isDefaultSet) { | ||
| roles.add(NRK_ROLE_DEFAULT); | ||
| } | ||
| } | ||
| roles.add(DASH_ROLE_MAIN); | ||
| subtitle.roles = Array.from(roles); | ||
| subtitle.roles.sort(); | ||
| logger.log( | ||
| `Track "${subtitle.label}" [translates]: Changed roles from "${rolesBefore.join("|")}" to "${subtitle.roles.join("|")}".` | ||
| ); | ||
| } | ||
| function chooseDefaultTrack(subtitles, context) { | ||
| console.log("Subtitles", subtitles); | ||
| const defaultTrack = context.isLive ? subtitles.find((subtitle) => subtitle.language === "no" && subtitle.roles?.includes(NRK_ROLE_TRANSLATES)) : subtitles.find((subtitle) => subtitle.language === "no" && subtitle.roles?.includes(NRK_ROLE_TRANSCRIBES)) ?? subtitles.find((subtitle) => subtitle.language === "no" && subtitle.roles?.includes(NRK_ROLE_TRANSLATES)); | ||
| if (defaultTrack !== void 0) { | ||
| defaultTrack.roles = Array.from(defaultTrack.roles ?? []); | ||
| defaultTrack.roles.push(NRK_ROLE_DEFAULT); | ||
| defaultTrack.roles.sort(); | ||
| logger.log(`No default track, choosing: "${defaultTrack.label}" "${defaultTrack.roles.join("|")}"`); | ||
| } else { | ||
| logger.log("No natural default track found."); | ||
| } | ||
| } | ||
| export { | ||
| isAutoSelectable, | ||
| isCaptions, | ||
| isDefault, | ||
| isForced, | ||
| tidyUpSubtitleRoles | ||
| }; |
+3
-3
| { | ||
| "name": "@nrk/player-elements", | ||
| "version": "17.1.46", | ||
| "version": "17.1.47", | ||
| "description": "", | ||
@@ -24,5 +24,5 @@ "author": "", | ||
| "eventemitter3": "5.0.4", | ||
| "@nrk/player-tracker": "8.1.3", | ||
| "@nrk/live-epg": "1.1.12", | ||
| "@nrk/player-psapi-client": "8.0.21", | ||
| "@nrk/player-tracker": "8.1.2" | ||
| "@nrk/player-psapi-client": "8.0.21" | ||
| }, | ||
@@ -29,0 +29,0 @@ "peerDependencies": { |
@@ -34,3 +34,2 @@ import { ReactiveElement } from "@nrkno/reactive-element"; | ||
| switch (key) { | ||
| // Left (seek back) | ||
| case keyboardShortcuts.seekBackwards.find((k) => k === key): { | ||
@@ -50,3 +49,2 @@ if ((event.ctrlKey || event.metaKey) && key === "j") { | ||
| } | ||
| // Right (seek fwd) | ||
| case keyboardShortcuts.seekForwards.find((k) => k === key): { | ||
@@ -71,3 +69,2 @@ if (!target || target.nodeName !== "INPUT") { | ||
| switch (key) { | ||
| // Enter & Space (toggle play) | ||
| case keyboardShortcuts.togglePlayPause.find((k) => k === key): { | ||
@@ -83,3 +80,2 @@ if (target?.nodeName !== "BUTTON") { | ||
| } | ||
| // K (toggle play) | ||
| case "k": { | ||
@@ -90,3 +86,2 @@ event.preventDefault(); | ||
| } | ||
| // 0-9 (jump in time) | ||
| case keyboardShortcuts.jumpInStream.find((k) => k === key): { | ||
@@ -97,3 +92,2 @@ event.preventDefault(); | ||
| } | ||
| // Home | ||
| case keyboardShortcuts.seekToStart.find((k) => k === key): { | ||
@@ -104,3 +98,2 @@ event.preventDefault(); | ||
| } | ||
| // End | ||
| case keyboardShortcuts.seekToEnd.find((k) => k === key): { | ||
@@ -111,3 +104,2 @@ event.preventDefault(); | ||
| } | ||
| // Up (volume up) | ||
| case keyboardShortcuts.volumeUp.find((k) => k === key): { | ||
@@ -120,3 +112,2 @@ if (!target || target.nodeName !== "INPUT") { | ||
| } | ||
| // Down (volume down) | ||
| case keyboardShortcuts.volumeDown.find((k) => k === key): { | ||
@@ -129,3 +120,2 @@ if (!target || target.nodeName !== "INPUT") { | ||
| } | ||
| // F (fullscreen toggle) | ||
| case keyboardShortcuts.toggleFullscreen.find((k) => k === key): { | ||
@@ -139,3 +129,2 @@ if (this.player.fullscreenState?.isActive) { | ||
| } | ||
| // M (muted toggle) | ||
| case keyboardShortcuts.toggleMute.find((k) => k === key): { | ||
@@ -146,7 +135,5 @@ event.preventDefault(); | ||
| } | ||
| // C (subtitles toggle) | ||
| case "c": { | ||
| break; | ||
| } | ||
| // P (pip toggle) | ||
| case keyboardShortcuts.togglePiP.find((k) => k === key): { | ||
@@ -161,3 +148,2 @@ event.preventDefault(); | ||
| } | ||
| // A & Z (zoom) | ||
| case "a": | ||
@@ -164,0 +150,0 @@ case "z": { |
@@ -34,3 +34,3 @@ import { version as playerCoreVersion } from "@nrk/player-core/types.js"; | ||
| const FONT_SIZE_BREAK_POINT = 500; | ||
| const PLAYER_ELEMENTS_VERSION = "17.1.46"; | ||
| const PLAYER_ELEMENTS_VERSION = "17.1.47"; | ||
| class PlayerElement extends DimensionsMixin( | ||
@@ -37,0 +37,0 @@ FocusVisibleMixin( |
| function generateSrcSet(webImages) { | ||
| if (webImages.length === 0) return ""; | ||
| if (webImages.length === 0) | ||
| return ""; | ||
| if (isWebImage(webImages)) { | ||
@@ -4,0 +5,0 @@ return webImages.map(({ uri, width }) => { |
Sorry, the diff of this file is too big to display
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
594886
0.81%78
2.63%13643
0.85%Updated