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
20 changes: 14 additions & 6 deletions src/common/TrackLabButtonOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@
* Shared flat button appearance for the sim. Rectangular and round push buttons
* default to SceneryStack's 3-D appearance; pass these options (or spread them
* into nested button options) for a flat look everywhere.
*
* Template-owned toolkit: each sim uses only some of these, so every export is tagged
* `@public` to tell dead-code checkers (knip) that an unused one is not dead code.
*/

import type { PlayPauseStepButtonGroupOptions, TimeControlNodeOptions } from "scenerystack/scenery-phet";
import { ButtonNode, type ComboBoxOptions } from "scenerystack/sun";
import TrackLabColors from "../TrackLabColors.js";

/** @public */
export const FLAT_BUTTON_APPEARANCE_OPTIONS = {
buttonAppearanceStrategy: ButtonNode.FlatAppearanceStrategy,
} as const;

/** Text on flat push buttons and combo-box items (always on a light control surface). */
/** Text on flat push buttons and combo-box items (always on a light control surface). @public */
export const LIGHT_SURFACE_TEXT_FILL = TrackLabColors.controlSurfaceTextColorProperty;

/**
* Combo-box chrome for panels. Item labels must use {@link LIGHT_SURFACE_TEXT_FILL}, not
* {@link TrackLabColors.textColorProperty} — that color is for labels on the dark panel fill.
*
* @public
*/
export const SIM_COMBO_BOX_OPTIONS = {
buttonFill: TrackLabColors.controlSurfaceColorProperty,
Expand All @@ -28,13 +34,13 @@ export const SIM_COMBO_BOX_OPTIONS = {
listStroke: TrackLabColors.panelBorderColorProperty,
} satisfies Pick<ComboBoxOptions, "buttonFill" | "listFill" | "buttonStroke" | "listStroke">;

/** Options for RectangularPushButton and NumberControl arrow buttons. */
export const FLAT_RECTANGULAR_BUTTON_OPTIONS = FLAT_BUTTON_APPEARANCE_OPTIONS;
/** Options for RectangularPushButton and NumberControl arrow buttons. @public */
export const FLAT_RECTANGULAR_BUTTON_OPTIONS = { ...FLAT_BUTTON_APPEARANCE_OPTIONS } as const;

/** Options for ResetAllButton (extends RoundPushButton). */
export const FLAT_RESET_ALL_BUTTON_OPTIONS = FLAT_BUTTON_APPEARANCE_OPTIONS;
/** Options for ResetAllButton (extends RoundPushButton). @public */
export const FLAT_RESET_ALL_BUTTON_OPTIONS = { ...FLAT_BUTTON_APPEARANCE_OPTIONS } as const;

/** Nested options for TimeControlNode play / pause / step round buttons. */
/** Nested options for TimeControlNode play / pause / step round buttons. @public */
export const FLAT_PLAY_PAUSE_STEP_BUTTON_OPTIONS = {
playPauseButtonOptions: FLAT_BUTTON_APPEARANCE_OPTIONS,
stepForwardButtonOptions: FLAT_BUTTON_APPEARANCE_OPTIONS,
Expand All @@ -44,6 +50,8 @@ export const FLAT_PLAY_PAUSE_STEP_BUTTON_OPTIONS = {
/**
* Speed radio labels for TimeControlNode. SceneryStack Text defaults to black, which
* is low-contrast on the sim's dark Default-mode panels.
*
* @public
*/
export const TIME_CONTROL_SPEED_RADIO_OPTIONS = {
speedRadioButtonGroupOptions: {
Expand Down
2 changes: 1 addition & 1 deletion tests/fuzz/fuzz.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function runFuzz(page: Page, fuzzUrl: string): Promise<void> {
await page.waitForTimeout(waitTime);
elapsed += waitTime;
try {
await page.evaluate(() => window.document.hasFocus);
await page.evaluate(() => window.document.hasFocus());
} catch {
break;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/helpers/memoryLeak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import { describe, expect, it } from "vitest";

/** @public */
export type DisposableObject = { dispose(): void };

export type DisposalCase = {
Expand All @@ -34,6 +35,8 @@ export type DisposalCase = {
* avoids the WeakRef macrotask-liveness pin. Without refs the loop always runs all
* passes, which on a slow gc() can exceed the Vitest testTimeout — pass refs when
* you have them.
*
* @public
*/
export async function forceGC(earlyExitRefs?: WeakRef<object> | readonly WeakRef<object>[]): Promise<void> {
const refs = earlyExitRefs === undefined ? [] : Array.isArray(earlyExitRefs) ? earlyExitRefs : [earlyExitRefs];
Expand All @@ -49,7 +52,7 @@ export async function forceGC(earlyExitRefs?: WeakRef<object> | readonly WeakRef
}
}

/** Create, dispose, and return a WeakRef to the disposed instance. */
/** Create, dispose, and return a WeakRef to the disposed instance. @public */
export function createAndDispose(create: () => DisposableObject): WeakRef<object> {
const instance = create();
const ref = new WeakRef<object>(instance);
Expand Down
2 changes: 2 additions & 0 deletions tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ if (typeof globalThis.Worker === "undefined") {
// its real type is a large overload union (widened further by @webgpu/types),
// and a spread argument cannot be applied to an overload union.
type LooseGetContext = (this: HTMLCanvasElement, contextId: string, ...args: unknown[]) => unknown;
// Detached on purpose: it is only ever invoked as `origGetContext.call(this, …)` below.
// oxlint-disable-next-line typescript/unbound-method
const origGetContext = HTMLCanvasElement.prototype.getContext as unknown as LooseGetContext;
HTMLCanvasElement.prototype.getContext = function (this: HTMLCanvasElement, contextId: string, ...args: unknown[]) {
if (contextId === "2d") {
Expand Down
Loading