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
10 changes: 9 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ Limit Explorer (`limit-explorer`) is a SceneryStack simulation scaffolded from S

## Compliance carve-outs

None yet.
- `memory-leak:PlotHandle` — file-private drag handle inside the plot/lesson view; not exported for `describeDisposalLeaks`.

## Testing

See the shared Vitest setup (`vitest.config.ts`, `tests/setup.ts`) and `tests/memory-leak.test.ts` for disposal coverage. Add sim-specific unit tests under `tests/` as physics and UI logic land.

## Accessibility

Follow [Baton/ACCESSIBILITY.md](https://github.com/OpenLyceum/Baton/blob/main/ACCESSIBILITY.md): PDOM names, per-screen `*ScreenSummaryContent`, and keyboard-help content. Document any intentional deviations under Compliance carve-outs.
12 changes: 12 additions & 0 deletions biome-plugins/no-math-round.grit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Flags Math.round(). Prefer roundSymmetric from scenerystack/dot so positive and
// negative values round the same way (see phetsims/dot#35).
// Suppress a deliberate use with: // biome-ignore lint/plugin/no-math-round: <reason>
language js

`Math.round($value)` as $call where {
register_diagnostic(
span = $call,
message = "Use roundSymmetric(value) from scenerystack/dot instead of Math.round(), which rounds positive and negative numbers differently.",
severity = "warn"
)
}
18 changes: 18 additions & 0 deletions biome-plugins/no-native-timer.grit
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Flags bare setTimeout / setInterval (and window.* forms). Sim code should step
// from the model/view step(dt) chain, or use stepTimer from scenerystack/axon when a
// delayed callback is truly needed. Method calls like stepTimer.setTimeout are allowed.
// Suppress a deliberate use with: // biome-ignore lint/plugin/no-native-timer: <reason>
language js

or {
`setTimeout($...)`,
`setInterval($...)`,
`window.setTimeout($...)`,
`window.setInterval($...)`
} as $call where {
register_diagnostic(
span = $call,
message = "Do not call setTimeout/setInterval in sim code; step from model/view step(dt), or use stepTimer from scenerystack/axon for a delayed callback.",
severity = "warn"
)
}
13 changes: 13 additions & 0 deletions biome-plugins/no-window-inner-size.grit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Flags window.innerWidth / window.innerHeight. Prefer Sim.dimensionProperty (or the
// screen's layoutBounds / visibleBounds) so layout tracks the sim display, not the
// browser chrome.
// Suppress a deliberate use with: // biome-ignore lint/plugin/no-window-inner-size: <reason>
language js

or { `window.innerWidth`, `window.innerHeight` } as $hit where {
register_diagnostic(
span = $hit,
message = "Use Sim.dimensionProperty (or layoutBounds/visibleBounds) instead of window.innerWidth/innerHeight.",
severity = "warn"
)
}
35 changes: 35 additions & 0 deletions biome-plugins/require-property-suffix.grit
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Flags axon Property instances whose binding name does not end in "Property".
// Covers same-line const/let/var and this.field for the common *Property constructors.
// Class fields (`public readonly foo = new NumberProperty(...)`, bare `foo = ...`) are
// not reliably matched by Biome GritQL — rename those in review or with a codemod.
// Type-only annotations are out of scope (PhET's rule is type-checker based).
// Suppress a deliberate use with: // biome-ignore lint/plugin/require-property-suffix: <reason>
// GritQL regexes here must use non-capturing groups (?:...); a plain (...) silently never matches.
language js

or {
`const $name = new $ctor($...)`,
`let $name = new $ctor($...)`,
`var $name = new $ctor($...)`,
`this.$name = new $ctor($...)`
} as $stmt where {
$ctor <: or {
`Property`,
`BooleanProperty`,
`NumberProperty`,
`StringProperty`,
`DerivedProperty`,
`DerivedStringProperty`,
`DynamicProperty`,
`TinyProperty`,
`EnumerationProperty`,
`StringUnionProperty`,
`ProfileColorProperty`
},
not $name <: r"(?s)(?:.*(?:Property|PROPERTY)|property|_property)$",
register_diagnostic(
span = $name,
message = "Axon Property bindings must end in \"Property\" (e.g. massProperty, not mass).",
severity = "warn"
)
}
15 changes: 13 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"assist": {
"actions": {
"source": {
"organizeImports": "on"
"organizeImports": "on",
"useSortedPackageJson": "on"
}
}
},
Expand Down Expand Up @@ -82,7 +83,9 @@
"style": {
"noCommonJs": "error",
"noDefaultExport": "off",
"noEnum": "error",
"noExportedImports": "warn",
"noNamespace": "error",
"noParameterAssign": "error",
"preset": "recommended",
"useBlockStatements": "error",
Expand All @@ -98,6 +101,7 @@
"strictCase": false
}
},
"useAsConstAssertion": "warn",
"useForOf": "warn",
"useImportType": "error",
"useNamingConvention": {
Expand Down Expand Up @@ -170,8 +174,15 @@
"plugins": [
"./biome-plugins/no-native-tofixed.grit",
"./biome-plugins/no-math-random.grit",
"./biome-plugins/no-math-round.grit",
"./biome-plugins/no-native-timer.grit",
"./biome-plugins/no-window-inner-size.grit",
"./biome-plugins/require-property-suffix.grit",
"./biome-plugins/no-hardcoded-text.grit",
{ "path": "./biome-plugins/no-inline-color.grit", "includes": ["**", "!**/*Colors.ts"] }
{
"path": "./biome-plugins/no-inline-color.grit",
"includes": ["**", "!**/*Colors.ts"]
}
],
"linter": {
"rules": {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 30 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
"name": "limit-explorer",
"private": true,
"version": "0.0.0",
"type": "module",
"private": true,
"description": "Explore one-sided limits and epsilon–delta bounds at discontinuities.",
"license": "AGPL-3.0-or-later",
"repository": {
"type": "git",
"url": "https://github.com/OpenLyceum/LimitExplorer.git"
},
"keywords": [
"simulation",
"SceneryStack",
Expand All @@ -17,33 +11,45 @@
"education",
"pwa"
],
"homepage": "https://openlyceum.github.io/LimitExplorer",
"repository": {
"type": "git",
"url": "https://github.com/OpenLyceum/LimitExplorer.git"
},
"license": "AGPL-3.0-or-later",
"type": "module",
"scripts": {
"start": "vite",
"dev": "vite",
"build": "tsc && vite build",
"build:single": "tsc && vite build --mode single",
"preview": "vite preview",
"lint": "biome check --error-on-warnings .",
"format": "biome format --write .",
"fix": "biome check --write .",
"check": "tsc --noEmit && tsc -p tsconfig.scripts.json --noEmit && tsc -p tsconfig.test.json --noEmit",
"check:unused": "knip",
"check:architecture": "depcruise src",
"check:unused": "knip",
"clean": "rm -rf dist",
"dev": "vite",
"fix": "biome check --write .",
"format": "biome format --write .",
"icons": "node scripts/generate-icons.ts",
"knip": "knip",
"lint": "biome check --error-on-warnings .",
"prepare": "test \"$(git rev-parse --show-toplevel 2>/dev/null)\" = \"$PWD\" && git config core.hooksPath .githooks || true",
"preview": "vite preview",
"release": "npm run check && npm run lint && npm run check:architecture && npm run build && npm test && npm version patch && git push && git push --tags",
"watch": "tsc --watch",
"start": "vite",
"test": "vitest run",
"test:watch": "vitest",
"test:architecture": "node --test tests/*.node-test.ts",
"test:fuzz": "node scripts/test-fuzz.ts",
"test:fuzz:quick": "node scripts/test-fuzz.ts 10",
"test:fuzz:long": "node scripts/test-fuzz.ts 300",
"test:fuzz:quick": "node scripts/test-fuzz.ts 10",
"test:soak": "npm run test:soak:headless && npm run test:soak:browser",
"test:soak:headless": "vitest run --config vitest.soak.config.ts",
"test:soak:browser": "npx playwright test tests/soak/browser.spec.ts",
"icons": "node scripts/generate-icons.ts",
"clean": "rm -rf dist",
"prepare": "test \"$(git rev-parse --show-toplevel 2>/dev/null)\" = \"$PWD\" && git config core.hooksPath .githooks || true",
"knip": "knip",
"test:architecture": "node --test tests/*.node-test.ts"
"test:soak:headless": "vitest run --config vitest.soak.config.ts",
"test:watch": "vitest",
"watch": "tsc --watch"
},
"overrides": {
"brace-expansion": "~5.0.12",
"lodash": "~4.18.1",
"three": "~0.125.2"
},
"dependencies": {
"scenerystack": "^3.0.0"
Expand All @@ -55,7 +61,7 @@
"@types/node": "^26.6.6",
"dependency-cruiser": "^18.8.0",
"happy-dom": "^21.0.4",
"knip": "^6.47.0",
"knip": "^6.46.1",
"png-to-ico": "^3.0.2",
"sharp": "^0.35.5",
"typescript": "^7.0.2",
Expand All @@ -66,11 +72,6 @@
"engines": {
"node": ">=26"
},
"overrides": {
"lodash": "~4.18.1",
"three": "~0.125.2",
"brace-expansion": "~5.0.12"
},
"devEngines": {
"runtime": {
"name": "node",
Expand Down
8 changes: 7 additions & 1 deletion src/approach/view/ApproachKeyboardHelpContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import {
SliderControlsKeyboardHelpSection,
TwoColumnKeyboardHelpContent,
} from "scenerystack/scenery-phet";
import { StringManager } from "../../i18n/StringManager.js";

export class ApproachKeyboardHelpContent extends TwoColumnKeyboardHelpContent {
public constructor() {
// The custom function's branches and point are moved with the arrow keys.
super(
[new MoveDraggableItemsKeyboardHelpSection(), new SliderControlsKeyboardHelpSection()],
[
new MoveDraggableItemsKeyboardHelpSection({
headingStringProperty: StringManager.getInstance().getLessonStrings().moveGraphHandlesStringProperty,
}),
new SliderControlsKeyboardHelpSection(),
],
[new BasicActionsKeyboardHelpSection()],
);
}
Expand Down
25 changes: 19 additions & 6 deletions src/common/LessonView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DerivedProperty, type NumberProperty, type ReadOnlyProperty, type TReadOnlyProperty } from "scenerystack/axon";
import { Bounds2, Dimension2, Range, Vector2 } from "scenerystack/dot";
import { Bounds2, Dimension2, Range, roundSymmetric, Vector2 } from "scenerystack/dot";
import { localeProperty } from "scenerystack/joist";
import { Shape } from "scenerystack/kite";
import {
Expand Down Expand Up @@ -81,7 +81,7 @@ export function slider(
thumbFill: Colors.accentColorProperty,
thumbTouchAreaXDilation: 7,
thumbTouchAreaYDilation: 7,
...(step ? { constrainValue: (x: number) => Math.round(x / step) * step, keyboardStep: step } : {}),
...(step ? { constrainValue: (x: number) => roundSymmetric(x / step) * step, keyboardStep: step } : {}),
});
return column(text(caption, 15, 285, true), control);
}
Expand Down Expand Up @@ -284,7 +284,11 @@ type HandleOptions = {
end?: () => void;
// For a quantity with no slider: the handle joins the tab order and the arrow
// keys move it by whole steps (Shift for quarter steps), passed as (dx, dy).
keyboard?: { name: TReadOnlyProperty<string>; step: (dx: number, dy: number) => void };
keyboard?: {
name: TReadOnlyProperty<string>;
direction: "leftRight" | "upDown";
step: (dx: number, dy: number) => void;
};
// Value label shown above the handle while it is hovered or dragged, read on each place().
readout?: () => string;
};
Expand Down Expand Up @@ -357,12 +361,21 @@ class PlotHandle extends Node {
if (keyboard) {
this.tagName = "div";
this.focusable = true;
this.ariaRole = "application";
this.accessibleNameBehavior = (_node, nodeOptions, name) => ({ ...nodeOptions, ariaLabel: name });
this.accessibleName = keyboard.name;
this.accessibleRoleDescription = "movable";
this.keyboardListener = new KeyboardDragListener({
keyboardDragDirection: keyboard.direction,
dragDelta: 1,
shiftDragDelta: 0.25,
drag: (_event, listener) => keyboard.step(listener.modelDelta.x, -listener.modelDelta.y),
positionProperty: {
get value() {
return Vector2.ZERO;
},
set value(delta: Vector2) {
keyboard.step(delta.x, -delta.y);
},
},
});
this.addInputListener(this.keyboardListener);
}
Expand Down Expand Up @@ -466,6 +479,6 @@ export class LessonView extends ScreenView {
this.addChild(sidebar);
this.addChild(notes);
this.addChild(resetButton);
this.addChild(new Node({ pdomOrder: [controls, resetButton] }));
this.addChild(new Node({ pdomOrder: [this.plot, controls, resetButton] }));
}
}
Loading
Loading