From a270492aca245a47907305088a0b95399b3ca47d Mon Sep 17 00:00:00 2001 From: martin veillette Date: Mon, 23 Nov 2026 23:56:58 -0500 Subject: [PATCH 1/4] Standardize homepage, AGENTS sections, and template pins. Set package homepage from the catalog, fill missing AGENTS headings, clear memory-leak inventory noise, and align knip/vitest with SceneryStackTemplate where drifted. --- AGENTS.md | 10 +++++++++- package-lock.json | 8 ++++---- package.json | 5 +++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index ca3994f..cb492e8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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. diff --git a/package-lock.json b/package-lock.json index b3d8c57..a98b153 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,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", @@ -7011,9 +7011,9 @@ } }, "node_modules/knip": { - "version": "6.47.0", - "resolved": "https://registry.npmjs.org/knip/-/knip-6.47.0.tgz", - "integrity": "sha512-nYmQnk0YqDXIJrYViJz88c8xw3tBDkpuAmofo58EkVPnKr6DnRKYtf6oIqcGVHZvXDE+gtmFuYx277/QsWng+A==", + "version": "6.46.1", + "resolved": "https://registry.npmjs.org/knip/-/knip-6.46.1.tgz", + "integrity": "sha512-5/ajqjZfmuv8O74+McrKBOSArKG6tsUgy6yJird36VZh9HiUq75qY4U39uqf9wjchEUOLrStuOZpFP057CZFRw==", "dev": true, "funding": [ { diff --git a/package.json b/package.json index dad525c..0a16f34 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,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", @@ -80,5 +80,6 @@ }, "allowScripts": { "@swc/core@1.16.22": true - } + }, + "homepage": "https://openlyceum.github.io/LimitExplorer" } From 18cf096722df1d6edb1d236e355442fbadf9cfd8 Mon Sep 17 00:00:00 2001 From: martin veillette Date: Tue, 24 Nov 2026 10:06:40 -0500 Subject: [PATCH 2/4] chore(biome): enforce no enum/namespace and as-const; sort package.json on fix Mirror erasableSyntaxOnly in the linter and enable useSortedPackageJson assist. --- biome.json | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/biome.json b/biome.json index 1d52328..f093ad4 100644 --- a/biome.json +++ b/biome.json @@ -3,7 +3,8 @@ "assist": { "actions": { "source": { - "organizeImports": "on" + "organizeImports": "on", + "useSortedPackageJson": "on" } } }, @@ -82,7 +83,9 @@ "style": { "noCommonJs": "error", "noDefaultExport": "off", + "noEnum": "error", "noExportedImports": "warn", + "noNamespace": "error", "noParameterAssign": "error", "preset": "recommended", "useBlockStatements": "error", @@ -98,6 +101,7 @@ "strictCase": false } }, + "useAsConstAssertion": "warn", "useForOf": "warn", "useImportType": "error", "useNamingConvention": { @@ -171,7 +175,10 @@ "./biome-plugins/no-native-tofixed.grit", "./biome-plugins/no-math-random.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": { From f38d7f3df921e3144881b5b1c9b143f251a7538a Mon Sep 17 00:00:00 2001 From: martin veillette Date: Tue, 24 Nov 2026 15:23:54 -0500 Subject: [PATCH 3/4] chore(biome): adopt bad-sim-text plugins and fix violations Add no-math-round, no-native-timer, no-window-inner-size, and require-property-suffix; replace Math.round with roundSymmetric and align Property names. --- biome-plugins/no-math-round.grit | 12 ++++ biome-plugins/no-native-timer.grit | 18 ++++++ biome-plugins/no-window-inner-size.grit | 13 ++++ biome-plugins/require-property-suffix.grit | 35 ++++++++++ biome.json | 4 ++ package.json | 60 ++++++++--------- .../view/ApproachKeyboardHelpContent.ts | 8 ++- src/common/LessonView.ts | 25 ++++++-- src/common/LimitExplorerView.ts | 64 ++++++++++++++++--- src/common/model/LimitExplorerModel.ts | 4 +- .../view/EpsilonDeltaKeyboardHelpContent.ts | 8 ++- src/i18n/strings_en.json | 6 ++ src/i18n/strings_es.json | 6 ++ src/i18n/strings_fr.json | 6 ++ tests/biome-plugins.node-test.ts | 53 ++++++++++++++- tests/browser/keyboard-drag.spec.ts | 42 ++++++++++++ 16 files changed, 314 insertions(+), 50 deletions(-) create mode 100644 biome-plugins/no-math-round.grit create mode 100644 biome-plugins/no-native-timer.grit create mode 100644 biome-plugins/no-window-inner-size.grit create mode 100644 biome-plugins/require-property-suffix.grit create mode 100644 tests/browser/keyboard-drag.spec.ts diff --git a/biome-plugins/no-math-round.grit b/biome-plugins/no-math-round.grit new file mode 100644 index 0000000..c00d4d3 --- /dev/null +++ b/biome-plugins/no-math-round.grit @@ -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: +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" + ) +} diff --git a/biome-plugins/no-native-timer.grit b/biome-plugins/no-native-timer.grit new file mode 100644 index 0000000..12db2dd --- /dev/null +++ b/biome-plugins/no-native-timer.grit @@ -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: +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" + ) +} diff --git a/biome-plugins/no-window-inner-size.grit b/biome-plugins/no-window-inner-size.grit new file mode 100644 index 0000000..a60a72f --- /dev/null +++ b/biome-plugins/no-window-inner-size.grit @@ -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: +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" + ) +} diff --git a/biome-plugins/require-property-suffix.grit b/biome-plugins/require-property-suffix.grit new file mode 100644 index 0000000..6ab614a --- /dev/null +++ b/biome-plugins/require-property-suffix.grit @@ -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: +// 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" + ) +} diff --git a/biome.json b/biome.json index f093ad4..20c80f1 100644 --- a/biome.json +++ b/biome.json @@ -174,6 +174,10 @@ "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", diff --git a/package.json b/package.json index 0a16f34..d237816 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" @@ -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", @@ -80,6 +81,5 @@ }, "allowScripts": { "@swc/core@1.16.22": true - }, - "homepage": "https://openlyceum.github.io/LimitExplorer" + } } diff --git a/src/approach/view/ApproachKeyboardHelpContent.ts b/src/approach/view/ApproachKeyboardHelpContent.ts index bfde2a8..9f3b823 100644 --- a/src/approach/view/ApproachKeyboardHelpContent.ts +++ b/src/approach/view/ApproachKeyboardHelpContent.ts @@ -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()], ); } diff --git a/src/common/LessonView.ts b/src/common/LessonView.ts index 851831a..8009c19 100644 --- a/src/common/LessonView.ts +++ b/src/common/LessonView.ts @@ -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 { @@ -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); } @@ -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; step: (dx: number, dy: number) => void }; + keyboard?: { + name: TReadOnlyProperty; + 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; }; @@ -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); } @@ -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] })); } } diff --git a/src/common/LimitExplorerView.ts b/src/common/LimitExplorerView.ts index 18cf35b..f69518c 100644 --- a/src/common/LimitExplorerView.ts +++ b/src/common/LimitExplorerView.ts @@ -1,4 +1,5 @@ import { Multilink, StringProperty } from "scenerystack/axon"; +import { roundSymmetric, toFixedNumber } from "scenerystack/dot"; import { localeProperty } from "scenerystack/joist"; import { StringUtils } from "scenerystack/phetcommon"; import { HBox, type Node } from "scenerystack/scenery"; @@ -172,19 +173,31 @@ export class LimitExplorerView extends LessonView { const plot = this.plot; const clamp = (value: number, min: number, max: number) => Math.max(min, Math.min(max, value)); - const snap = (value: number, step: number) => Math.round(value / step) * step; + const snap = (value: number, step: number) => roundSymmetric(value / step) * step; if (approach) { this.plot.onDrag((x) => { const property = x < 0 ? model.left : model.right; property.value = clamp(Math.abs(x) / model.span, 0.005, 1); }); - const probe = (property: typeof model.left, fill: typeof Colors.secondaryColorProperty) => + const probe = ( + property: typeof model.left, + fill: typeof Colors.secondaryColorProperty, + name: typeof strings.leftProbeStringProperty, + outward: -1 | 1, + ) => plot.handle({ fill, cursor: "ew-resize", drag: (x) => { property.value = clamp(Math.abs(plot.modelX(x)) / model.span, 0.005, 1); }, + keyboard: { + name, + direction: "leftRight", + step: (dx) => { + property.value = clamp(toFixedNumber(property.value + outward * dx * 0.02, 4), 0.005, 1); + }, + }, readout: () => { const x = property === model.left ? model.leftX : model.rightX; const y = f(x); @@ -192,8 +205,14 @@ export class LimitExplorerView extends LessonView { }, }); this.handles = [ - [probe(model.left, Colors.secondaryColorProperty), () => model.leftX], - [probe(model.right, Colors.tertiaryColorProperty), () => model.rightX], + [ + probe(model.left, Colors.secondaryColorProperty, strings.leftProbeHandleStringProperty, -1), + () => model.leftX, + ], + [ + probe(model.right, Colors.tertiaryColorProperty, strings.rightProbeHandleStringProperty, 1), + () => model.rightX, + ], ]; } else { const target = plot.handle({ @@ -201,6 +220,13 @@ export class LimitExplorerView extends LessonView { drag: (_x, y) => { model.target.value = clamp(snap(plot.modelY(y), 0.05), -2, 2); }, + keyboard: { + name: strings.targetHandleStringProperty, + direction: "upDown", + step: (_dx, dy) => { + model.target.value = clamp(toFixedNumber(model.target.value + dy * 0.04, 4), -2, 2); + }, + }, readout: () => `L = ${format(model.target.value)}`, }); const epsilon = plot.handle({ @@ -209,6 +235,13 @@ export class LimitExplorerView extends LessonView { drag: (_x, y) => { model.epsilon.value = clamp(snap(Math.abs(plot.modelY(y) - model.target.value), 0.05), 0.05, 2); }, + keyboard: { + name: strings.epsilonHandleStringProperty, + direction: "upDown", + step: (_dx, dy) => { + model.epsilon.value = clamp(toFixedNumber(model.epsilon.value + dy * 0.04, 4), 0.05, 2); + }, + }, readout: () => `ε = ${format(model.epsilon.value)}`, }); const delta = plot.handle({ @@ -217,12 +250,21 @@ export class LimitExplorerView extends LessonView { drag: (x) => { model.delta.value = clamp(snap(Math.abs(plot.modelX(x)), 0.001), 0.001, 1); }, + keyboard: { + name: strings.deltaHandleStringProperty, + direction: "leftRight", + step: (dx) => { + model.delta.value = clamp(toFixedNumber(model.delta.value + dx * 0.004, 4), 0.001, 1); + }, + }, readout: () => `δ = ${format(model.delta.value, 3)}`, }); - this.placeBandHandles = (extent) => { + this.placeBandHandles = (extent, horizontal) => { target.place(plot.plotX(0.75 * model.span), plot.plotY(model.target.value)); epsilon.place(plot.plotX(-0.75 * model.span), plot.plotY(model.target.value + model.epsilon.value)); - delta.place(plot.plotX(model.delta.value), plot.plotY(-0.8 * extent)); + // Keep the handle reachable when zooming in past the band boundary. + delta.place(plot.plotX(Math.min(model.delta.value, horizontal)), plot.plotY(-0.8 * extent)); + delta.opacity = model.delta.value <= horizontal ? 1 : 0.55; }; } @@ -237,7 +279,11 @@ export class LimitExplorerView extends LessonView { model.shape(key, plot.modelY(y) + offset); }, readout, - keyboard: { name, step: (_dx, dy) => model.shape(key, model.piece.value[key] + dy * PIECE_KEY_STEP) }, + keyboard: { + name, + direction: "upDown", + step: (_dx, dy) => model.shape(key, model.piece.value[key] + dy * PIECE_KEY_STEP), + }, }); this.pieceHandles = [ [part("left", strings.leftBranchStringProperty, () => `x → 0⁻ : ${format(model.piece.value.left)}`), "left"], @@ -282,7 +328,7 @@ export class LimitExplorerView extends LessonView { /** Approach probes: each handle rides the graph at its probe's x. */ private readonly handles: ReadonlyArray, () => number]> = []; - private readonly placeBandHandles: (extent: number) => void = () => undefined; + private readonly placeBandHandles: (extent: number, horizontal: number) => void = () => undefined; private draw(model: LimitExplorerModel): void { const plot = this.plot; @@ -363,7 +409,7 @@ export class LimitExplorerView extends LessonView { handle.place(plot.plotX(x()), plot.plotY(f(x()) ?? 0)); } } else { - this.placeBandHandles(extent); + this.placeBandHandles(extent, horizontal); const x = counterexample(example, model.target.value, model.epsilon.value, model.delta.value, piece); if (x !== null) { plot.point(x, f(x) ?? 0, Colors.secondaryColorProperty); diff --git a/src/common/model/LimitExplorerModel.ts b/src/common/model/LimitExplorerModel.ts index 2816a1d..f49d002 100644 --- a/src/common/model/LimitExplorerModel.ts +++ b/src/common/model/LimitExplorerModel.ts @@ -1,5 +1,5 @@ import { NumberProperty, Property } from "scenerystack/axon"; -import { dotRandom } from "scenerystack/dot"; +import { dotRandom, roundSymmetric } from "scenerystack/dot"; import type { TModel } from "scenerystack/joist"; export const examples = ["continuous", "removable", "jump", "oscillation", "custom"] as const; @@ -190,7 +190,7 @@ export class LimitExplorerModel implements TModel { /** Sets one part of the custom function, snapped to 0.05 and kept on the graph. */ public shape(part: keyof Piece, value: number): void { - const snapped = Math.max(-pieceRange, Math.min(pieceRange, Math.round(value * 20) / 20)); + const snapped = Math.max(-pieceRange, Math.min(pieceRange, roundSymmetric(value * 20) / 20)); if (snapped !== this.piece.value[part]) { this.piece.value = { ...this.piece.value, [part]: snapped }; } diff --git a/src/epsilon-delta/view/EpsilonDeltaKeyboardHelpContent.ts b/src/epsilon-delta/view/EpsilonDeltaKeyboardHelpContent.ts index fa46253..ac6c0ee 100644 --- a/src/epsilon-delta/view/EpsilonDeltaKeyboardHelpContent.ts +++ b/src/epsilon-delta/view/EpsilonDeltaKeyboardHelpContent.ts @@ -4,12 +4,18 @@ import { SliderControlsKeyboardHelpSection, TwoColumnKeyboardHelpContent, } from "scenerystack/scenery-phet"; +import { StringManager } from "../../i18n/StringManager.js"; export class EpsilonDeltaKeyboardHelpContent 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()], ); } diff --git a/src/i18n/strings_en.json b/src/i18n/strings_en.json index 273082c..75f4bdd 100644 --- a/src/i18n/strings_en.json +++ b/src/i18n/strings_en.json @@ -29,6 +29,12 @@ "removable": "Removable discontinuity", "jump": "Jump discontinuity", "oscillation": "Oscillation", + "leftProbeHandle": "Left graph probe", + "rightProbeHandle": "Right graph probe", + "targetHandle": "Target value L", + "epsilonHandle": "Epsilon band", + "deltaHandle": "Delta band", + "moveGraphHandles": "Move graph handles", "leftProbe": "Left distance within view", "rightProbe": "Right distance within view", "left": "Left probe", diff --git a/src/i18n/strings_es.json b/src/i18n/strings_es.json index 843883f..8259b9d 100644 --- a/src/i18n/strings_es.json +++ b/src/i18n/strings_es.json @@ -29,6 +29,12 @@ "removable": "Discontinuidad evitable", "jump": "Discontinuidad de salto", "oscillation": "Oscilación", + "leftProbeHandle": "Sonda izquierda de la gráfica", + "rightProbeHandle": "Sonda derecha de la gráfica", + "targetHandle": "Valor objetivo L", + "epsilonHandle": "Banda épsilon", + "deltaHandle": "Banda delta", + "moveGraphHandles": "Mover los controles de la gráfica", "leftProbe": "Distancia izquierda en la vista", "rightProbe": "Distancia derecha en la vista", "left": "Sonda izquierda", diff --git a/src/i18n/strings_fr.json b/src/i18n/strings_fr.json index 022b033..6cf95c0 100644 --- a/src/i18n/strings_fr.json +++ b/src/i18n/strings_fr.json @@ -29,6 +29,12 @@ "removable": "Discontinuité amovible", "jump": "Discontinuité par saut", "oscillation": "Oscillation", + "leftProbeHandle": "Sonde gauche du graphique", + "rightProbeHandle": "Sonde droite du graphique", + "targetHandle": "Valeur cible L", + "epsilonHandle": "Bande epsilon", + "deltaHandle": "Bande delta", + "moveGraphHandles": "Déplacer les poignées du graphique", "leftProbe": "Distance à gauche dans la vue", "rightProbe": "Distance à droite dans la vue", "left": "Sonde gauche", diff --git a/tests/biome-plugins.node-test.ts b/tests/biome-plugins.node-test.ts index 8238845..137cae6 100644 --- a/tests/biome-plugins.node-test.ts +++ b/tests/biome-plugins.node-test.ts @@ -63,6 +63,54 @@ test("no-math-random flags Math.random() and leaves dotRandom alone", () => { assert.deepEqual(lines(hits, "dotRandom"), [1]); }); +test("no-math-round flags Math.round() and leaves roundSymmetric alone", () => { + const hits = lint({ + "src/a.ts": "export const a = Math.round(1.5);\nexport const b = roundSymmetric(1.5);\n", + }); + assert.deepEqual(lines(hits, "roundSymmetric"), [1]); +}); + +test("no-native-timer flags bare and window timers, allows stepTimer", () => { + const hits = lint({ + "src/a.ts": [ + "setTimeout(() => {}, 0);", + "setInterval(() => {}, 0);", + "window.setTimeout(() => {}, 0);", + "window.setInterval(() => {}, 0);", + "stepTimer.setTimeout(() => {}, 0);", + "stepTimer.setInterval(() => {}, 0);", + "", + ].join("\n"), + }); + assert.deepEqual(lines(hits, "stepTimer"), [1, 2, 3, 4]); +}); + +test("no-window-inner-size flags window.innerWidth/Height", () => { + const hits = lint({ + "src/a.ts": "const w = window.innerWidth;\nconst h = window.innerHeight;\nconst d = dimensionProperty;\n", + }); + assert.deepEqual(lines(hits, "dimensionProperty"), [1, 2]); +}); + +test("require-property-suffix flags Property bindings without Property suffix", () => { + const hits = lint({ + "src/a.ts": [ + "const mass = new NumberProperty(1);", + "const massProperty = new NumberProperty(1);", + "const details = new DerivedProperty([x], (v) => v);", + "const detailsProperty = new DerivedProperty([x], (v) => v);", + "this.visible = new BooleanProperty(true);", + "this.visibleProperty = new BooleanProperty(true);", + // Class fields are not reliably matched by Biome GritQL yet. + "class D {", + " public readonly ignored = new NumberProperty(0);", + "}", + "", + ].join("\n"), + }); + assert.deepEqual(lines(hits, "Property"), [1, 3, 5]); +}); + test("no-hardcoded-text flags literal display words only", () => { const hits = lint({ "src/a.ts": [ @@ -116,6 +164,9 @@ test("no-inline-color flags hardcoded colors outside *Colors.ts", () => { }); test("plugins only run under src/", () => { - const hits = lint({ "scripts/a.ts": 'Math.random(); new Text("Mass"); new Color(1, 2, 3);\n' }); + const hits = lint({ + "scripts/a.ts": + 'Math.random(); Math.round(1); setTimeout(() => {}, 0); window.innerWidth; const mass = new NumberProperty(1); new Text("Mass"); new Color(1, 2, 3);\n', + }); assert.deepEqual(hits, []); }); diff --git a/tests/browser/keyboard-drag.spec.ts b/tests/browser/keyboard-drag.spec.ts new file mode 100644 index 0000000..ebbab1a --- /dev/null +++ b/tests/browser/keyboard-drag.spec.ts @@ -0,0 +1,42 @@ +import { expect, test } from "@playwright/test"; + +test("the approach probes move independently and respect their side of the limit", async ({ page }) => { + await page.goto("/?ea&screens=1"); + const left = page.getByRole("application", { name: "Left graph probe", exact: true }); + const right = page.getByRole("application", { name: "Right graph probe", exact: true }); + await left.focus(); + await page.keyboard.press("Shift+Tab"); + await page.keyboard.press("Tab"); + await expect(left).toBeFocused(); + await page.keyboard.press("ArrowRight"); + await expect(page.getByRole("slider", { name: "Left distance within view" })).toHaveAttribute( + "aria-valuenow", + "0.43", + ); + await page.keyboard.press("Tab"); + await expect(right).toBeFocused(); + await page.keyboard.press("Shift+ArrowRight"); + await expect(page.getByRole("slider", { name: "Right distance within view" })).toHaveAttribute( + "aria-valuenow", + "0.455", + ); +}); + +test("the target and epsilon and delta bands respond along their own axes", async ({ page }) => { + await page.goto("/?ea&screens=2"); + for (const { name, key, slider, value } of [ + { name: "Target value L", key: "ArrowUp", slider: "L", value: "0.04" }, + { name: "Epsilon band", key: "Shift+ArrowDown", slider: "ε", value: "0.49" }, + { name: "Delta band", key: "Shift+ArrowRight", slider: "δ", value: "0.401" }, + ]) { + const handle = page.getByRole("application", { name, exact: true }); + await handle.press(key); + await expect(page.getByRole("slider", { name: slider, exact: true })).toHaveAttribute("aria-valuenow", value); + await expect(handle).toBeFocused(); + } + await page.getByRole("slider", { name: "Zoom factor", exact: true }).press("End"); + const delta = page.getByRole("application", { name: "Delta band", exact: true }); + await delta.press("Shift+ArrowLeft"); + await expect(page.getByRole("slider", { name: "δ", exact: true })).toHaveAttribute("aria-valuenow", "0.4"); + await expect(delta).toBeFocused(); +}); From 7fb573feb713faa05e5503f08c81229b06461429 Mon Sep 17 00:00:00 2001 From: martin veillette Date: Tue, 24 Nov 2026 15:35:11 -0500 Subject: [PATCH 4/4] Fix validation after the fleet Property naming update --- src/common/model/LimitExplorerModel.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/model/LimitExplorerModel.ts b/src/common/model/LimitExplorerModel.ts index f49d002..75cc445 100644 --- a/src/common/model/LimitExplorerModel.ts +++ b/src/common/model/LimitExplorerModel.ts @@ -92,6 +92,7 @@ const DELTA_STEP = 0.001; * The largest δ in [DELTA_STEP, 1] for which no input in the punctured band * leaves the ε-band, by bisection: if a δ works, every smaller δ does too. */ +/** @internal Directly tested numerical helper. */ export function largestDelta(example: Example, limit: number, epsilon: number, piece = defaultPiece): number { const works = (delta: number) => counterexample(example, limit, epsilon, delta, piece) === null; if (works(1)) {