Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/player/src/shader-options.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, expect, it } from "vitest";
import { getShaderModeFromElement, SHADER_LOADING_ATTR } from "./shader-options.js";

const modeOf = (value: string | null) => {
const el = document.createElement("div");
if (value !== null) el.setAttribute(SHADER_LOADING_ATTR, value);
return getShaderModeFromElement(el);
};

describe("getShaderModeFromElement", () => {
it.each([
[null, "composition"],
["", "composition"],
[" ", "composition"],
["none", "none"],
[" OFF ", "none"],
["false", "none"],
["0", "none"],
["player", "player"],
["True", "player"],
["1", "player"],
["on", "player"],
["composition", "composition"],
["sometimes", "composition"],
["constructor", "composition"],
["__proto__", "composition"],
])("reads %j as %s", (value, mode) => {
expect(modeOf(value)).toBe(mode);
});
});
31 changes: 12 additions & 19 deletions packages/player/src/shader-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,19 @@ function normalizeShaderCaptureScale(value: string | null): string | null {
return String(Math.min(1, Math.max(0.25, parsed)));
}

const SHADER_LOADING_WORDS = new Map<string, ShaderLoadingMode>([
["none", "none"],
["false", "none"],
["0", "none"],
["off", "none"],
["player", "player"],
["true", "player"],
["1", "player"],
["on", "player"],
]);

function normalizeShaderLoadingMode(value: string | null): ShaderLoadingMode {
if (value === null || value.trim() === "") return "composition";
const normalized = value.trim().toLowerCase();
if (
normalized === "none" ||
normalized === "false" ||
normalized === "0" ||
normalized === "off"
) {
return "none";
}
if (
normalized === "player" ||
normalized === "true" ||
normalized === "1" ||
normalized === "on"
) {
return "player";
}
return "composition";
return SHADER_LOADING_WORDS.get(value?.trim().toLowerCase() ?? "") ?? "composition";
}

/** Drop one of our own keys from raw `a=1&b=2` pairs, matched by name so that
Expand Down
Loading