web: Mark TypeScript enums as const
Unlike regular enums, const enums are completely removed during compilation, and as such are zero-cost in bundle size terms. Since it is not possible to query the possible values of a const enum at runtime, adapt the `autoplay` and `unmuteOverlay` validation logic.
This commit is contained in:
parent
0b4d6e6a1c
commit
d27e29bd26
|
@ -1,4 +1,4 @@
|
||||||
export enum AutoPlay {
|
export const enum AutoPlay {
|
||||||
/**
|
/**
|
||||||
* The player should automatically play the movie as soon as it is loaded.
|
* The player should automatically play the movie as soon as it is loaded.
|
||||||
*
|
*
|
||||||
|
@ -32,7 +32,7 @@ export enum AutoPlay {
|
||||||
* When letterboxed, black bars will be rendered around the exterior
|
* When letterboxed, black bars will be rendered around the exterior
|
||||||
* margins of the content.
|
* margins of the content.
|
||||||
*/
|
*/
|
||||||
export enum Letterbox {
|
export const enum Letterbox {
|
||||||
/**
|
/**
|
||||||
* The content will never be letterboxed.
|
* The content will never be letterboxed.
|
||||||
*/
|
*/
|
||||||
|
@ -53,7 +53,7 @@ export enum Letterbox {
|
||||||
* When the player is muted, this controls whether or not Ruffle will show a
|
* When the player is muted, this controls whether or not Ruffle will show a
|
||||||
* "click to unmute" overlay on top of the movie.
|
* "click to unmute" overlay on top of the movie.
|
||||||
*/
|
*/
|
||||||
export enum UnmuteOverlay {
|
export const enum UnmuteOverlay {
|
||||||
/**
|
/**
|
||||||
* Show an overlay explaining that the movie is muted.
|
* Show an overlay explaining that the movie is muted.
|
||||||
*/
|
*/
|
||||||
|
@ -68,7 +68,7 @@ export enum UnmuteOverlay {
|
||||||
/**
|
/**
|
||||||
* Console logging level.
|
* Console logging level.
|
||||||
*/
|
*/
|
||||||
export enum LogLevel {
|
export const enum LogLevel {
|
||||||
Error = "error",
|
Error = "error",
|
||||||
Warn = "warn",
|
Warn = "warn",
|
||||||
Info = "info",
|
Info = "info",
|
||||||
|
|
|
@ -24,7 +24,7 @@ export const FLASH_ACTIVEX_CLASSID =
|
||||||
const RUFFLE_ORIGIN = "https://ruffle.rs";
|
const RUFFLE_ORIGIN = "https://ruffle.rs";
|
||||||
const DIMENSION_REGEX = /^\s*(\d+(\.\d+)?(%)?)/;
|
const DIMENSION_REGEX = /^\s*(\d+(\.\d+)?(%)?)/;
|
||||||
|
|
||||||
enum PanicError {
|
const enum PanicError {
|
||||||
Unknown,
|
Unknown,
|
||||||
CSPConflict,
|
CSPConflict,
|
||||||
FileProtocol,
|
FileProtocol,
|
||||||
|
@ -427,25 +427,17 @@ export class RufflePlayer extends HTMLElement {
|
||||||
this.container.style.visibility = "";
|
this.container.style.visibility = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const autoplay = Object.values(Object(AutoPlay)).includes(
|
// Treat unspecified and invalid values as `AutoPlay.Auto`.
|
||||||
config.autoplay
|
|
||||||
)
|
|
||||||
? config.autoplay
|
|
||||||
: AutoPlay.Auto;
|
|
||||||
const unmuteVisibility = Object.values(Object(UnmuteOverlay)).includes(
|
|
||||||
config.unmuteOverlay
|
|
||||||
)
|
|
||||||
? config.unmuteOverlay
|
|
||||||
: UnmuteOverlay.Visible;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
autoplay == AutoPlay.On ||
|
config.autoplay === AutoPlay.On ||
|
||||||
(autoplay == AutoPlay.Auto && this.audioState() === "running")
|
(config.autoplay !== AutoPlay.Off &&
|
||||||
|
this.audioState() === "running")
|
||||||
) {
|
) {
|
||||||
this.play();
|
this.play();
|
||||||
|
|
||||||
if (this.audioState() !== "running") {
|
if (this.audioState() !== "running") {
|
||||||
if (unmuteVisibility === UnmuteOverlay.Visible) {
|
// Treat unspecified and invalid values as `UnmuteOverlay.Visible`.
|
||||||
|
if (config.unmuteOverlay !== UnmuteOverlay.Hidden) {
|
||||||
this.unmuteOverlay.style.display = "block";
|
this.unmuteOverlay.style.display = "block";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1251,7 +1243,7 @@ export class RufflePlayer extends HTMLElement {
|
||||||
/**
|
/**
|
||||||
* Describes the loading state of an SWF movie.
|
* Describes the loading state of an SWF movie.
|
||||||
*/
|
*/
|
||||||
export enum ReadyState {
|
export const enum ReadyState {
|
||||||
/**
|
/**
|
||||||
* No movie is loaded, or no information is yet available about the movie.
|
* No movie is loaded, or no information is yet available about the movie.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue