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
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ decisions: [`doc/implementation-notes.md`](doc/implementation-notes.md).
## PWA

After `npm run build`, the sim is installable offline via Workbox (`dist/manifest.webmanifest`).

## Compliance carve-outs

None.
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"
)
}
10 changes: 9 additions & 1 deletion 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,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",
Expand Down
57 changes: 29 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
"name": "titration-lab",
"private": true,
"version": "0.0.0",
"type": "module",
"private": true,
"description": "Acid–base titration for General Chemistry: a burette-and-indicator lab with an unknown, exact titration curves for strong, weak and polyprotic acids and bases, and how to choose an indicator.",
"license": "AGPL-3.0-or-later",
"repository": {
"type": "git",
"url": "https://github.com/OpenLyceum/TitrationLab.git"
},
"keywords": [
"simulation",
"SceneryStack",
Expand All @@ -23,33 +17,45 @@
"education",
"pwa"
],
"homepage": "https://openlyceum.github.io/TitrationLab",
"repository": {
"type": "git",
"url": "https://github.com/OpenLyceum/TitrationLab.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 @@ -72,11 +78,6 @@
"engines": {
"node": ">=26"
},
"overrides": {
"lodash": "~4.18.1",
"three": "~0.125.2",
"brace-expansion": "~5.0.12"
},
"devEngines": {
"runtime": {
"name": "node",
Expand Down
4 changes: 2 additions & 2 deletions src/common/model/TitrationCurve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TITRATION_CURVE_SETTINGS } from "../../TitrationLabConstants.js";
* Volumes are in mL and concentrations in mol/L; amounts are returned in mmol (mL × mol/L).
*/

import { Vector2 } from "scenerystack/dot";
import { roundSymmetric, Vector2 } from "scenerystack/dot";
import { KEY_POINT_TOLERANCE, PKW, STOICHIOMETRIC_TOLERANCE } from "../../TitrationLabConstants.js";
import { type Analyte, analyteMixture, isStrong, isTitratedWithBase, titrantMixture } from "./Analytes.js";
import { alphaFractions, type Mixture, mix, solvePH } from "./ChargeBalanceSolver.js";
Expand Down Expand Up @@ -228,7 +228,7 @@ export function regionAt(setup: TitrationSetup, titrantVolume: number): Region {
const totalVolume = setup.analyteVolume + titrantVolume;
const progress = (setup.titrantConcentration * titrantVolume) / amount;
const base = isTitratedWithBase(analyte);
const whole = Math.round(progress);
const whole = roundSymmetric(progress);
const atWhole = Math.abs(progress - whole) <= STOICHIOMETRIC_TOLERANCE * Math.max(1, progress);

if (isStrong(analyte)) {
Expand Down
13 changes: 4 additions & 9 deletions src/common/view/formatValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ const SUPERSCRIPTS: Record<string, string> = {
"9": "⁹",
};

/** Typed lookup in a getNestedStringProperties group (keys are suffixed "StringProperty"). */
function lookup<K extends string>(group: object, key: K): ReadOnlyProperty<string> {
return (group as Record<string, ReadOnlyProperty<string>>)[`${key}StringProperty`] as ReadOnlyProperty<string>;
}

/** Fixed decimals with a true minus sign. */
export function fixed(value: number, decimals: number): string {
return toFixed(value, decimals).replace("-", MINUS);
Expand Down Expand Up @@ -62,7 +57,7 @@ export function scientific(value: number, significant = 2): string {
}

export function analyteNameProperty(id: AnalyteId | "unknownAcid"): ReadOnlyProperty<string> {
return lookup(StringManager.getInstance().getAnalyteNames(), id);
return StringManager.getInstance().getAnalyteNames()[`${id}StringProperty`];
}

/** "Acetic acid, CH<sub>3</sub>COOH" (RichText), following the locale. */
Expand All @@ -77,7 +72,7 @@ export function analyteLabelProperty(analyte: Analyte): TReadOnlyProperty<string
}

export function indicatorNameProperty(id: IndicatorId): ReadOnlyProperty<string> {
return lookup(StringManager.getInstance().getIndicatorNames(), id);
return StringManager.getInstance().getIndicatorNames()[`${id}StringProperty`];
}

/** Indicator name, or "None". */
Expand All @@ -88,7 +83,7 @@ export function indicatorName(indicator: Indicator | null): string {
}

export function colorName(color: PerceivedColor): string {
return lookup(StringManager.getInstance().getColorNames(), color).value;
return StringManager.getInstance().getColorNames()[`${color}StringProperty`].value;
}

/** Name of a region; numbered when the analyte has more than one equivalence point. */
Expand Down Expand Up @@ -119,7 +114,7 @@ export function regionName(region: Region, analyte: Analyte): string {

/** RichText statement of a textbook approximation. */
export function methodText(method: ApproximationMethod): string {
return lookup(StringManager.getInstance().getCommonStrings().methods, method).value;
return StringManager.getInstance().getCommonStrings().methods[`${method}StringProperty`].value;
}

/** "Volume of NaOH added (mL)" for the analyte's titrant. */
Expand Down
4 changes: 2 additions & 2 deletions src/indicators/view/IndicatorsScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { INDICATORS_SCREEN_VIEW_SETTINGS } from "../../TitrationLabConstants.js"
*/

import { DerivedProperty } from "scenerystack/axon";
import { Dimension2 } from "scenerystack/dot";
import { Dimension2, roundSymmetric } from "scenerystack/dot";
import { optionize } from "scenerystack/phet-core";
import { StringUtils } from "scenerystack/phetcommon";
import { HBox, Node, Text, VBox } from "scenerystack/scenery";
Expand Down Expand Up @@ -73,7 +73,7 @@ export class IndicatorsScreenView extends ScreenView {
keyboardStep: INDICATORS_SCREEN_VIEW_SETTINGS.PH_SLIDER_KEYBOARD_STEP,
shiftKeyboardStep: INDICATORS_SCREEN_VIEW_SETTINGS.PH_SLIDER_SHIFT_KEYBOARD_STEP,
pageKeyboardStep: INDICATORS_SCREEN_VIEW_SETTINGS.PH_SLIDER_PAGE_KEYBOARD_STEP,
constrainValue: (value: number) => Math.round(value * 20) / 20,
constrainValue: (value: number) => roundSymmetric(value * 20) / 20,
accessibleName: strings.solutionPHStringProperty,
});
for (let pH = PH_RANGE.min; pH <= PH_RANGE.max; pH += 2) {
Expand Down
4 changes: 2 additions & 2 deletions src/lab/view/BuretteNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ export class BuretteNode extends Node {
readingText.top = lens.y + LENS_RADIUS + BURETTE_NODE_SETTINGS.CONSTRUCTOR_TOP_OFFSET;
});

const openFraction = new DerivedProperty([model.flowRateProperty], (rate) => rate / FLOW_RATE_RANGE.max);
openFraction.link((fraction) => {
const openFractionProperty = new DerivedProperty([model.flowRateProperty], (rate) => rate / FLOW_RATE_RANGE.max);
openFractionProperty.link((fraction) => {
handle.rotation = (fraction * Math.PI) / 2;
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/lab/view/LabScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ export class LabScreenView extends ScreenView {
chart.chartTransform.modelToViewXY(0, 0).plusXY(CHART_WIDTH / 2, -CHART_HEIGHT / 2),
);
});
const hintVisible = new DerivedProperty([model.meterInFlaskProperty], (inFlask) => !inFlask);
hintVisible.link((visible) => {
const hintVisibleProperty = new DerivedProperty([model.meterInFlaskProperty], (inFlask) => !inFlask);
hintVisibleProperty.link((visible) => {
hint.visible = visible && model.measuredPoints.length === 0;
});

Expand Down
4 changes: 2 additions & 2 deletions src/lab/view/PHMeterNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class PHMeterNode extends Node {
public constructor(pHProperty: TReadOnlyProperty<number>, meterInProperty: TReadOnlyProperty<boolean>) {
super();
const common = StringManager.getInstance().getCommonStrings();
const reading = new DerivedProperty(
const readingProperty = new DerivedProperty(
[pHProperty, meterInProperty, common.noReadingStringProperty],
(pH, inFlask, noReading) => (inFlask ? formatPH(pH) : noReading),
);
Expand All @@ -40,7 +40,7 @@ export class PHMeterNode extends Node {
fill: TitrationLabColors.meterScreenColorProperty,
},
);
const value = new Text(reading, {
const value = new Text(readingProperty, {
font: new PhetFont({ size: PH_METER_NODE_SETTINGS.VALUE_FONT_SIZE, weight: "bold", family: "monospace" }),
fill: TitrationLabColors.meterTextColorProperty,
maxWidth: WIDTH - PH_METER_NODE_SETTINGS.VALUE_MAX_WIDTH_OFFSET,
Expand Down
Loading
Loading