fix(lotus): transparent-theme contrast guard; phone-only rail shrink; live URL params
- lotusTransparent without lotusTheme warns and applies the theme anyway; name tags/header/footer get a subtle text-shadow + backdrop blur under body.lotus-transparent (#21). - Landscape filmstrip shrink requires (pointer: coarse) so a short desktop/PiP window isn't reflowed as a phone (#32). - lotusParam re-reads window.location on every call (#33). Fixes #21 Fixes #32 Fixes #33 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
co-authored by
Claude Opus 5
parent
c7494e68ca
commit
e9a59336c7
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
Copyright 2026 Lotus Guild
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
|
||||
vi.mock("../widget", () => ({ widget: null }));
|
||||
|
||||
import { lotusFlag, lotusParam, lotusSendToHost } from "./lotusWidget";
|
||||
import { LotusWidgetActions } from "./lotusActions";
|
||||
|
||||
/**
|
||||
* Point `window.location` at a URL for the duration of one assertion. Uses a
|
||||
* path relative to the current origin — `pushState` throws a `SecurityError`
|
||||
* on a cross-origin URL, and jsdom's default test origin doesn't match a
|
||||
* hard-coded `http://localhost/`.
|
||||
*/
|
||||
function setLocation(path: string): void {
|
||||
window.history.pushState({}, "", path);
|
||||
}
|
||||
|
||||
describe("lotusParam / lotusFlag", () => {
|
||||
afterEach(() => {
|
||||
setLocation("/");
|
||||
});
|
||||
|
||||
test("reads a param from the query string", () => {
|
||||
setLocation("/?lotusTheme=1");
|
||||
expect(lotusParam("lotusTheme")).toBe("1");
|
||||
});
|
||||
|
||||
test("reads a param from the hash fragment's query portion", () => {
|
||||
setLocation("/#/room?lotusTransparent=1");
|
||||
expect(lotusParam("lotusTransparent")).toBe("1");
|
||||
});
|
||||
|
||||
test("the hash fragment wins over the query string for the same key", () => {
|
||||
setLocation("/?lotusTheme=fromQuery#/room?lotusTheme=fromHash");
|
||||
expect(lotusParam("lotusTheme")).toBe("fromHash");
|
||||
});
|
||||
|
||||
test("falls back to the query string for keys absent from the hash", () => {
|
||||
setLocation("/?onlyInQuery=1#/room?lotusTheme=1");
|
||||
expect(lotusParam("onlyInQuery")).toBe("1");
|
||||
});
|
||||
|
||||
test("returns null when the param is present nowhere", () => {
|
||||
setLocation("/#/room");
|
||||
expect(lotusParam("missing")).toBeNull();
|
||||
});
|
||||
|
||||
test.each([
|
||||
["1", true],
|
||||
["true", true],
|
||||
["0", false],
|
||||
["false", false],
|
||||
[null, false],
|
||||
])("lotusFlag treats %s as %s", (value, expected) => {
|
||||
setLocation(value === null ? "/" : `/?f=${value}`);
|
||||
expect(lotusFlag("f")).toBe(expected);
|
||||
});
|
||||
|
||||
// [lotus #33] lotusParam must re-derive from window.location on every call
|
||||
// rather than caching the first read, so a later navigation (e.g. lobby ->
|
||||
// in-call) that rewrites the URL is picked up.
|
||||
test("re-reads window.location on every call instead of caching the first result", () => {
|
||||
setLocation("/?lotusTheme=1");
|
||||
expect(lotusParam("lotusTheme")).toBe("1");
|
||||
|
||||
setLocation("/?lotusTheme=0");
|
||||
expect(lotusParam("lotusTheme")).toBe("0");
|
||||
|
||||
setLocation("/");
|
||||
expect(lotusParam("lotusTheme")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("lotusSendToHost", () => {
|
||||
test("returns false when no widget transport is available", () => {
|
||||
expect(lotusSendToHost(LotusWidgetActions.CallState, {})).toBe(false);
|
||||
});
|
||||
});
|
||||
+13
-14
@@ -21,27 +21,26 @@ import type { LotusWidgetActions } from "./lotusActions";
|
||||
|
||||
export { LotusWidgetActions } from "./lotusActions";
|
||||
|
||||
let cachedParams: URLSearchParams | undefined;
|
||||
|
||||
/**
|
||||
* Read a URL param from either the query string or the hash fragment (Element
|
||||
* Call passes widget params via both depending on host), without depending on
|
||||
* EC's own `getUrlParams` parser (keeps the rebase surface small).
|
||||
*
|
||||
* [lotus #33] Re-parsed from `window.location` on every call instead of being
|
||||
* cached at first use: parsing is cheap, and caching risked returning a
|
||||
* stale value if `location.hash`/`search` are ever rewritten after first
|
||||
* read (e.g. during in-iframe navigation).
|
||||
*/
|
||||
export function lotusParam(name: string): string | null {
|
||||
if (!cachedParams) {
|
||||
// Match EC's own ParamParser precedence: the hash fragment wins over the
|
||||
// query string. So seed from the fragment first, then fill gaps from query.
|
||||
const hash = window.location.hash.replace(/^#\/?/, "");
|
||||
const hashQuery = hash.includes("?")
|
||||
? hash.slice(hash.indexOf("?") + 1)
|
||||
: "";
|
||||
cachedParams = new URLSearchParams(hashQuery);
|
||||
for (const [k, v] of new URLSearchParams(window.location.search)) {
|
||||
if (!cachedParams.has(k)) cachedParams.append(k, v);
|
||||
}
|
||||
// Match EC's own ParamParser precedence: the hash fragment wins over the
|
||||
// query string. So seed from the fragment first, then fill gaps from query.
|
||||
const hash = window.location.hash.replace(/^#\/?/, "");
|
||||
const hashQuery = hash.includes("?") ? hash.slice(hash.indexOf("?") + 1) : "";
|
||||
const params = new URLSearchParams(hashQuery);
|
||||
for (const [k, v] of new URLSearchParams(window.location.search)) {
|
||||
if (!params.has(k)) params.append(k, v);
|
||||
}
|
||||
return cachedParams.get(name);
|
||||
return params.get(name);
|
||||
}
|
||||
|
||||
/** Whether a boolean-ish Lotus feature flag is enabled. */
|
||||
|
||||
Reference in New Issue
Block a user