@classytic/labs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +105 -0
- package/dist/biology/enzyme-rate/index.d.mts +1 -0
- package/dist/biology/enzyme-rate/preset.d.mts +25 -0
- package/dist/biology/enzyme-rate/preset.mjs +256 -0
- package/dist/biology/genetic-cross/core.d.mts +64 -0
- package/dist/biology/genetic-cross/core.mjs +147 -0
- package/dist/biology/genetic-cross/grid.mjs +239 -0
- package/dist/biology/genetic-cross/index.d.mts +3 -0
- package/dist/biology/genetic-cross/preset.d.mts +26 -0
- package/dist/biology/genetic-cross/preset.mjs +184 -0
- package/dist/biology/genetic-cross/sex-linked.d.mts +27 -0
- package/dist/biology/genetic-cross/sex-linked.mjs +226 -0
- package/dist/biology/index.d.mts +11 -0
- package/dist/biology/index.mjs +12 -0
- package/dist/biology/photosynthesis-factors/index.d.mts +1 -0
- package/dist/biology/photosynthesis-factors/preset.d.mts +25 -0
- package/dist/biology/photosynthesis-factors/preset.mjs +270 -0
- package/dist/biology/punnett-cross/index.d.mts +1 -0
- package/dist/biology/punnett-cross/preset.d.mts +27 -0
- package/dist/biology/punnett-cross/preset.mjs +21 -0
- package/dist/biology/respiration/index.d.mts +1 -0
- package/dist/biology/respiration/preset.d.mts +17 -0
- package/dist/biology/respiration/preset.mjs +179 -0
- package/dist/biology/sequence/central-dogma.d.mts +17 -0
- package/dist/biology/sequence/central-dogma.mjs +339 -0
- package/dist/biology/sequence/core.d.mts +38 -0
- package/dist/biology/sequence/core.mjs +178 -0
- package/dist/biology/sequence/index.d.mts +3 -0
- package/dist/biology/sequence/preset.d.mts +20 -0
- package/dist/biology/sequence/preset.mjs +235 -0
- package/dist/blocks/accounting.d.mts +142 -0
- package/dist/blocks/accounting.mjs +446 -0
- package/dist/blocks/authoring.d.mts +12 -0
- package/dist/blocks/authoring.mjs +705 -0
- package/dist/blocks/biology.d.mts +197 -0
- package/dist/blocks/biology.mjs +513 -0
- package/dist/blocks/chem.d.mts +128 -0
- package/dist/blocks/chem.mjs +486 -0
- package/dist/blocks/circuits.d.mts +86 -0
- package/dist/blocks/circuits.mjs +348 -0
- package/dist/blocks/discrete.d.mts +62 -0
- package/dist/blocks/discrete.mjs +314 -0
- package/dist/blocks/economics.d.mts +56 -0
- package/dist/blocks/economics.mjs +203 -0
- package/dist/blocks/geography.d.mts +58 -0
- package/dist/blocks/geography.mjs +115 -0
- package/dist/blocks/geometry.d.mts +28 -0
- package/dist/blocks/geometry.mjs +160 -0
- package/dist/blocks/ict.d.mts +65 -0
- package/dist/blocks/ict.mjs +197 -0
- package/dist/blocks/index.d.mts +4555 -0
- package/dist/blocks/index.mjs +120 -0
- package/dist/blocks/lab-block.d.mts +16 -0
- package/dist/blocks/lab-block.mjs +74 -0
- package/dist/blocks/lab-config.d.mts +23 -0
- package/dist/blocks/lab-config.mjs +200 -0
- package/dist/blocks/lab-gallery.d.mts +30 -0
- package/dist/blocks/lab-gallery.mjs +208 -0
- package/dist/blocks/language.d.mts +349 -0
- package/dist/blocks/language.mjs +750 -0
- package/dist/blocks/lesson.d.mts +43 -0
- package/dist/blocks/lesson.mjs +140 -0
- package/dist/blocks/math.d.mts +411 -0
- package/dist/blocks/math.mjs +1536 -0
- package/dist/blocks/ml.d.mts +84 -0
- package/dist/blocks/ml.mjs +146 -0
- package/dist/blocks/physics.d.mts +259 -0
- package/dist/blocks/physics.mjs +868 -0
- package/dist/blocks/statistics.d.mts +29 -0
- package/dist/blocks/statistics.mjs +123 -0
- package/dist/catalog/index.d.mts +3 -0
- package/dist/catalog/index.mjs +8 -0
- package/dist/catalog/registry.d.mts +46 -0
- package/dist/catalog/registry.mjs +56 -0
- package/dist/catalog/templates.d.mts +11 -0
- package/dist/catalog/templates.mjs +141 -0
- package/dist/chem/battery.d.mts +16 -0
- package/dist/chem/battery.mjs +311 -0
- package/dist/chem/bohr-atom.d.mts +16 -0
- package/dist/chem/bohr-atom.mjs +212 -0
- package/dist/chem/diffusion/asset.mjs +76 -0
- package/dist/chem/diffusion/index.d.mts +1 -0
- package/dist/chem/diffusion/preset.d.mts +15 -0
- package/dist/chem/diffusion/preset.mjs +188 -0
- package/dist/chem/electrochem/index.d.mts +1 -0
- package/dist/chem/electrochem/preset.d.mts +23 -0
- package/dist/chem/electrochem/preset.mjs +402 -0
- package/dist/chem/equilibrium/index.d.mts +1 -0
- package/dist/chem/equilibrium/preset.d.mts +36 -0
- package/dist/chem/equilibrium/preset.mjs +416 -0
- package/dist/chem/gas-box/index.d.mts +1 -0
- package/dist/chem/gas-box/preset.d.mts +27 -0
- package/dist/chem/gas-box/preset.mjs +395 -0
- package/dist/chem/index.d.mts +16 -0
- package/dist/chem/index.mjs +17 -0
- package/dist/chem/kinetics/index.d.mts +1 -0
- package/dist/chem/kinetics/preset.d.mts +31 -0
- package/dist/chem/kinetics/preset.mjs +478 -0
- package/dist/chem/periodic-trends/index.d.mts +1 -0
- package/dist/chem/periodic-trends/preset.d.mts +21 -0
- package/dist/chem/periodic-trends/preset.mjs +831 -0
- package/dist/chem/reaction-lab.d.mts +18 -0
- package/dist/chem/reaction-lab.mjs +165 -0
- package/dist/chem/reaction-profile.d.mts +21 -0
- package/dist/chem/reaction-profile.mjs +287 -0
- package/dist/chem/solution/dilution.d.mts +27 -0
- package/dist/chem/solution/dilution.mjs +199 -0
- package/dist/chem/solution/field.d.mts +30 -0
- package/dist/chem/solution/field.mjs +145 -0
- package/dist/chem/solution/index.d.mts +3 -0
- package/dist/chem/solution/solution-box.d.mts +28 -0
- package/dist/chem/solution/solution-box.mjs +140 -0
- package/dist/chem/stoichiometry/index.d.mts +1 -0
- package/dist/chem/stoichiometry/preset.d.mts +29 -0
- package/dist/chem/stoichiometry/preset.mjs +392 -0
- package/dist/chem/titration/index.d.mts +1 -0
- package/dist/chem/titration/preset.d.mts +29 -0
- package/dist/chem/titration/preset.mjs +436 -0
- package/dist/circuits/ac-dc/asset.mjs +295 -0
- package/dist/circuits/ac-dc/index.d.mts +1 -0
- package/dist/circuits/ac-dc/preset.d.mts +16 -0
- package/dist/circuits/ac-dc/preset.mjs +134 -0
- package/dist/circuits/capacitor-leak/index.d.mts +1 -0
- package/dist/circuits/capacitor-leak/preset.d.mts +32 -0
- package/dist/circuits/capacitor-leak/preset.mjs +271 -0
- package/dist/circuits/circuit/asset.d.mts +6 -0
- package/dist/circuits/circuit/asset.mjs +367 -0
- package/dist/circuits/circuit/index.d.mts +2 -0
- package/dist/circuits/circuit/preset.d.mts +46 -0
- package/dist/circuits/circuit/preset.mjs +235 -0
- package/dist/circuits/circuit-builder.d.mts +30 -0
- package/dist/circuits/circuit-builder.mjs +412 -0
- package/dist/circuits/circuit-lab.d.mts +20 -0
- package/dist/circuits/circuit-lab.mjs +400 -0
- package/dist/circuits/index.d.mts +7 -0
- package/dist/circuits/index.mjs +8 -0
- package/dist/commerce/accounting/core.d.mts +48 -0
- package/dist/commerce/accounting/core.mjs +57 -0
- package/dist/commerce/accounting/equation-balance.d.mts +35 -0
- package/dist/commerce/accounting/equation-balance.mjs +292 -0
- package/dist/commerce/accounting/index.d.mts +4 -0
- package/dist/commerce/accounting/journal-poster.d.mts +29 -0
- package/dist/commerce/accounting/journal-poster.mjs +472 -0
- package/dist/commerce/accounting/statement-sorter.d.mts +25 -0
- package/dist/commerce/accounting/statement-sorter.mjs +304 -0
- package/dist/commerce/economics/core.d.mts +33 -0
- package/dist/commerce/economics/core.mjs +26 -0
- package/dist/commerce/economics/demand-shift-vs-move.d.mts +35 -0
- package/dist/commerce/economics/demand-shift-vs-move.mjs +324 -0
- package/dist/commerce/economics/elasticity-revenue.d.mts +31 -0
- package/dist/commerce/economics/elasticity-revenue.mjs +253 -0
- package/dist/commerce/economics/index.d.mts +4 -0
- package/dist/commerce/economics/market-equilibrium.d.mts +33 -0
- package/dist/commerce/economics/market-equilibrium.mjs +340 -0
- package/dist/commerce/index.d.mts +9 -0
- package/dist/commerce/index.mjs +10 -0
- package/dist/core/easing.d.mts +28 -0
- package/dist/core/easing.mjs +66 -0
- package/dist/core/index.d.mts +10 -0
- package/dist/core/index.mjs +11 -0
- package/dist/core/numeric.d.mts +37 -0
- package/dist/core/numeric.mjs +75 -0
- package/dist/core/reactive.d.mts +24 -0
- package/dist/core/reactive.mjs +51 -0
- package/dist/core/rng.d.mts +21 -0
- package/dist/core/rng.mjs +39 -0
- package/dist/core/tex.d.mts +14 -0
- package/dist/core/tex.mjs +44 -0
- package/dist/core/timeline.d.mts +34 -0
- package/dist/core/timeline.mjs +77 -0
- package/dist/core/util.d.mts +19 -0
- package/dist/core/util.mjs +31 -0
- package/dist/discrete/arrangements/preset.d.mts +28 -0
- package/dist/discrete/arrangements/preset.mjs +304 -0
- package/dist/discrete/bayes/preset.d.mts +33 -0
- package/dist/discrete/bayes/preset.mjs +476 -0
- package/dist/discrete/binomial/preset.d.mts +25 -0
- package/dist/discrete/binomial/preset.mjs +333 -0
- package/dist/discrete/core/combinatorics.d.mts +23 -0
- package/dist/discrete/core/combinatorics.mjs +57 -0
- package/dist/discrete/core/inclusionExclusion.d.mts +19 -0
- package/dist/discrete/core/inclusionExclusion.mjs +30 -0
- package/dist/discrete/core/pigeonhole.d.mts +15 -0
- package/dist/discrete/core/pigeonhole.mjs +24 -0
- package/dist/discrete/core/probability.d.mts +29 -0
- package/dist/discrete/core/probability.mjs +43 -0
- package/dist/discrete/core/sets.d.mts +21 -0
- package/dist/discrete/core/sets.mjs +45 -0
- package/dist/discrete/counting-slots/preset.d.mts +30 -0
- package/dist/discrete/counting-slots/preset.mjs +553 -0
- package/dist/discrete/counting-tree/index.d.mts +1 -0
- package/dist/discrete/counting-tree/preset.d.mts +44 -0
- package/dist/discrete/counting-tree/preset.mjs +364 -0
- package/dist/discrete/expected-value/preset.d.mts +28 -0
- package/dist/discrete/expected-value/preset.mjs +352 -0
- package/dist/discrete/hypergeometric/preset.d.mts +25 -0
- package/dist/discrete/hypergeometric/preset.mjs +330 -0
- package/dist/discrete/index.d.mts +26 -0
- package/dist/discrete/index.mjs +27 -0
- package/dist/discrete/karnaugh/index.d.mts +1 -0
- package/dist/discrete/karnaugh/preset.d.mts +30 -0
- package/dist/discrete/karnaugh/preset.mjs +452 -0
- package/dist/discrete/lln/asset.mjs +206 -0
- package/dist/discrete/lln/index.d.mts +1 -0
- package/dist/discrete/lln/preset.d.mts +17 -0
- package/dist/discrete/lln/preset.mjs +152 -0
- package/dist/discrete/logic-circuit/index.d.mts +1 -0
- package/dist/discrete/logic-circuit/preset.d.mts +47 -0
- package/dist/discrete/logic-circuit/preset.mjs +307 -0
- package/dist/discrete/monte-carlo/index.d.mts +1 -0
- package/dist/discrete/monte-carlo/preset.d.mts +64 -0
- package/dist/discrete/monte-carlo/preset.mjs +446 -0
- package/dist/discrete/monty-hall/index.d.mts +1 -0
- package/dist/discrete/monty-hall/preset.d.mts +23 -0
- package/dist/discrete/monty-hall/preset.mjs +491 -0
- package/dist/discrete/outcome-builder/preset.d.mts +24 -0
- package/dist/discrete/outcome-builder/preset.mjs +283 -0
- package/dist/discrete/pascal/preset.d.mts +24 -0
- package/dist/discrete/pascal/preset.mjs +372 -0
- package/dist/discrete/sample-space/index.d.mts +1 -0
- package/dist/discrete/sample-space/preset.d.mts +42 -0
- package/dist/discrete/sample-space/preset.mjs +395 -0
- package/dist/discrete/selection/preset.d.mts +33 -0
- package/dist/discrete/selection/preset.mjs +406 -0
- package/dist/discrete/truth-table/index.d.mts +1 -0
- package/dist/discrete/truth-table/preset.d.mts +30 -0
- package/dist/discrete/truth-table/preset.mjs +456 -0
- package/dist/discrete/venn/index.d.mts +1 -0
- package/dist/discrete/venn/preset.d.mts +32 -0
- package/dist/discrete/venn/preset.mjs +461 -0
- package/dist/geography/cycle-lab/index.d.mts +1 -0
- package/dist/geography/cycle-lab/preset.d.mts +25 -0
- package/dist/geography/cycle-lab/preset.mjs +254 -0
- package/dist/geography/cycles.d.mts +21 -0
- package/dist/geography/cycles.mjs +205 -0
- package/dist/geography/index.d.mts +4 -0
- package/dist/geography/index.mjs +5 -0
- package/dist/geometry/board/index.d.mts +1 -0
- package/dist/geometry/board/preset.d.mts +71 -0
- package/dist/geometry/board/preset.mjs +148 -0
- package/dist/geometry/builder.d.mts +18 -0
- package/dist/geometry/builder.mjs +332 -0
- package/dist/geometry/index.d.mts +4 -0
- package/dist/geometry/index.mjs +5 -0
- package/dist/geometry/intersecting-circles.d.mts +17 -0
- package/dist/geometry/intersecting-circles.mjs +104 -0
- package/dist/ict/index.d.mts +5 -0
- package/dist/ict/index.mjs +6 -0
- package/dist/ict/number-systems/base-odometer.d.mts +34 -0
- package/dist/ict/number-systems/base-odometer.mjs +160 -0
- package/dist/ict/number-systems/bit-grouper.d.mts +32 -0
- package/dist/ict/number-systems/bit-grouper.mjs +190 -0
- package/dist/ict/number-systems/index.d.mts +4 -0
- package/dist/ict/number-systems/place-value-dial.d.mts +29 -0
- package/dist/ict/number-systems/place-value-dial.mjs +153 -0
- package/dist/ict/number-systems/wheel.d.mts +73 -0
- package/dist/ict/number-systems/wheel.mjs +279 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +11 -0
- package/dist/kit/anim.mjs +52 -0
- package/dist/kit/annotate.mjs +116 -0
- package/dist/kit/answer-check.d.mts +38 -0
- package/dist/kit/answer-check.mjs +65 -0
- package/dist/kit/asset-util.mjs +15 -0
- package/dist/kit/controls.mjs +77 -0
- package/dist/kit/cycle.d.mts +44 -0
- package/dist/kit/cycle.mjs +188 -0
- package/dist/kit/diagram.mjs +176 -0
- package/dist/kit/electronics.mjs +357 -0
- package/dist/kit/expr-analysis.d.mts +37 -0
- package/dist/kit/expr-analysis.mjs +111 -0
- package/dist/kit/frame.d.mts +70 -0
- package/dist/kit/frame.mjs +205 -0
- package/dist/kit/freq-tree.mjs +99 -0
- package/dist/kit/gameshow.mjs +315 -0
- package/dist/kit/index.d.mts +5 -0
- package/dist/kit/index.mjs +6 -0
- package/dist/kit/logic-gates.d.mts +6 -0
- package/dist/kit/logic-gates.mjs +210 -0
- package/dist/kit/molecules.mjs +178 -0
- package/dist/kit/pedagogy.d.mts +126 -0
- package/dist/kit/pedagogy.mjs +331 -0
- package/dist/kit/play.d.mts +21 -0
- package/dist/kit/play.mjs +52 -0
- package/dist/kit/probability.mjs +141 -0
- package/dist/kit/proportion.mjs +112 -0
- package/dist/kit/reaction.mjs +102 -0
- package/dist/kit/rich.d.mts +10 -0
- package/dist/kit/rich.mjs +21 -0
- package/dist/kit/scale.mjs +230 -0
- package/dist/kit/space.mjs +326 -0
- package/dist/kit/steps.d.mts +24 -0
- package/dist/kit/steps.mjs +57 -0
- package/dist/kit/thermal.mjs +289 -0
- package/dist/language/agreement/index.d.mts +1 -0
- package/dist/language/agreement/preset.d.mts +27 -0
- package/dist/language/agreement/preset.mjs +113 -0
- package/dist/language/article-lens/index.d.mts +1 -0
- package/dist/language/article-lens/preset.d.mts +31 -0
- package/dist/language/article-lens/preset.mjs +125 -0
- package/dist/language/deck.d.mts +45 -0
- package/dist/language/deck.mjs +61 -0
- package/dist/language/icon.d.mts +40 -0
- package/dist/language/icon.mjs +73 -0
- package/dist/language/index.d.mts +10 -0
- package/dist/language/index.mjs +11 -0
- package/dist/language/preposition-scene/index.d.mts +1 -0
- package/dist/language/preposition-scene/preset.d.mts +34 -0
- package/dist/language/preposition-scene/preset.mjs +234 -0
- package/dist/language/sentence-builder/index.d.mts +1 -0
- package/dist/language/sentence-builder/preset.d.mts +32 -0
- package/dist/language/sentence-builder/preset.mjs +122 -0
- package/dist/language/transform/index.d.mts +1 -0
- package/dist/language/transform/preset.d.mts +31 -0
- package/dist/language/transform/preset.mjs +137 -0
- package/dist/language/ui.d.mts +53 -0
- package/dist/language/ui.mjs +88 -0
- package/dist/language/word-match/index.d.mts +1 -0
- package/dist/language/word-match/preset.d.mts +22 -0
- package/dist/language/word-match/preset.mjs +148 -0
- package/dist/math/area-model/asset.d.mts +6 -0
- package/dist/math/area-model/asset.mjs +270 -0
- package/dist/math/area-model/index.d.mts +2 -0
- package/dist/math/area-model/preset.d.mts +29 -0
- package/dist/math/area-model/preset.mjs +243 -0
- package/dist/math/balance-algebra/asset.d.mts +6 -0
- package/dist/math/balance-algebra/asset.mjs +150 -0
- package/dist/math/balance-algebra/index.d.mts +2 -0
- package/dist/math/balance-algebra/preset.d.mts +30 -0
- package/dist/math/balance-algebra/preset.mjs +228 -0
- package/dist/math/derivation.d.mts +22 -0
- package/dist/math/derivation.mjs +113 -0
- package/dist/math/derivative-explorer/index.d.mts +1 -0
- package/dist/math/derivative-explorer/preset.d.mts +19 -0
- package/dist/math/derivative-explorer/preset.mjs +227 -0
- package/dist/math/function-machine/index.d.mts +1 -0
- package/dist/math/function-machine/preset.d.mts +21 -0
- package/dist/math/function-machine/preset.mjs +177 -0
- package/dist/math/gradient-descent.d.mts +23 -0
- package/dist/math/gradient-descent.mjs +473 -0
- package/dist/math/grapher/index.d.mts +1 -0
- package/dist/math/grapher/preset.d.mts +40 -0
- package/dist/math/grapher/preset.mjs +313 -0
- package/dist/math/harmonic-form/index.d.mts +1 -0
- package/dist/math/harmonic-form/preset.d.mts +21 -0
- package/dist/math/harmonic-form/preset.mjs +387 -0
- package/dist/math/index.d.mts +25 -0
- package/dist/math/index.mjs +26 -0
- package/dist/math/integral-explorer/index.d.mts +1 -0
- package/dist/math/integral-explorer/preset.d.mts +23 -0
- package/dist/math/integral-explorer/preset.mjs +217 -0
- package/dist/math/interactive/index.d.mts +1 -0
- package/dist/math/interactive/preset.d.mts +72 -0
- package/dist/math/interactive/preset.mjs +202 -0
- package/dist/math/limit-explorer/index.d.mts +1 -0
- package/dist/math/limit-explorer/preset.d.mts +19 -0
- package/dist/math/limit-explorer/preset.mjs +216 -0
- package/dist/math/linear-system/index.d.mts +1 -0
- package/dist/math/linear-system/preset.d.mts +28 -0
- package/dist/math/linear-system/preset.mjs +164 -0
- package/dist/math/mystery-bucket/asset.d.mts +6 -0
- package/dist/math/mystery-bucket/asset.mjs +145 -0
- package/dist/math/mystery-bucket/index.d.mts +2 -0
- package/dist/math/mystery-bucket/preset.d.mts +36 -0
- package/dist/math/mystery-bucket/preset.mjs +116 -0
- package/dist/math/number-line/index.d.mts +1 -0
- package/dist/math/number-line/preset.d.mts +24 -0
- package/dist/math/number-line/preset.mjs +142 -0
- package/dist/math/parabola/index.d.mts +1 -0
- package/dist/math/parabola/preset.d.mts +13 -0
- package/dist/math/parabola/preset.mjs +79 -0
- package/dist/math/pattern/asset.d.mts +6 -0
- package/dist/math/pattern/asset.mjs +102 -0
- package/dist/math/pattern/index.d.mts +2 -0
- package/dist/math/pattern/preset.d.mts +32 -0
- package/dist/math/pattern/preset.mjs +294 -0
- package/dist/math/triangle-trig/index.d.mts +1 -0
- package/dist/math/triangle-trig/preset.d.mts +47 -0
- package/dist/math/triangle-trig/preset.mjs +245 -0
- package/dist/math/trig-explorer.d.mts +18 -0
- package/dist/math/trig-explorer.mjs +209 -0
- package/dist/ml/boundary/index.d.mts +1 -0
- package/dist/ml/boundary/preset.d.mts +24 -0
- package/dist/ml/boundary/preset.mjs +385 -0
- package/dist/ml/classifier/index.d.mts +1 -0
- package/dist/ml/classifier/preset.d.mts +25 -0
- package/dist/ml/classifier/preset.mjs +315 -0
- package/dist/ml/index.d.mts +6 -0
- package/dist/ml/index.mjs +7 -0
- package/dist/ml/kmeans/index.d.mts +1 -0
- package/dist/ml/kmeans/preset.d.mts +33 -0
- package/dist/ml/kmeans/preset.mjs +236 -0
- package/dist/ml/knn/index.d.mts +1 -0
- package/dist/ml/knn/preset.d.mts +28 -0
- package/dist/ml/knn/preset.mjs +279 -0
- package/dist/ml/regression/index.d.mts +1 -0
- package/dist/ml/regression/preset.d.mts +32 -0
- package/dist/ml/regression/preset.mjs +394 -0
- package/dist/physics/atwood/index.d.mts +1 -0
- package/dist/physics/atwood/preset.d.mts +23 -0
- package/dist/physics/atwood/preset.mjs +312 -0
- package/dist/physics/bullet-walls/index.d.mts +1 -0
- package/dist/physics/bullet-walls/preset.d.mts +28 -0
- package/dist/physics/bullet-walls/preset.mjs +373 -0
- package/dist/physics/carnot/index.d.mts +1 -0
- package/dist/physics/carnot/preset.d.mts +27 -0
- package/dist/physics/carnot/preset.mjs +427 -0
- package/dist/physics/circular-motion/index.d.mts +1 -0
- package/dist/physics/circular-motion/preset.d.mts +25 -0
- package/dist/physics/circular-motion/preset.mjs +293 -0
- package/dist/physics/collision-track/index.d.mts +1 -0
- package/dist/physics/collision-track/preset.d.mts +27 -0
- package/dist/physics/collision-track/preset.mjs +352 -0
- package/dist/physics/efficiency/index.d.mts +1 -0
- package/dist/physics/efficiency/preset.d.mts +33 -0
- package/dist/physics/efficiency/preset.mjs +343 -0
- package/dist/physics/electric-field/index.d.mts +1 -0
- package/dist/physics/electric-field/preset.d.mts +15 -0
- package/dist/physics/electric-field/preset.mjs +306 -0
- package/dist/physics/energy-skate/index.d.mts +1 -0
- package/dist/physics/energy-skate/preset.d.mts +25 -0
- package/dist/physics/energy-skate/preset.mjs +254 -0
- package/dist/physics/entropy/index.d.mts +1 -0
- package/dist/physics/entropy/preset.d.mts +18 -0
- package/dist/physics/entropy/preset.mjs +416 -0
- package/dist/physics/expansion/index.d.mts +1 -0
- package/dist/physics/expansion/preset.d.mts +26 -0
- package/dist/physics/expansion/preset.mjs +609 -0
- package/dist/physics/exponential/asset.mjs +221 -0
- package/dist/physics/exponential/index.d.mts +1 -0
- package/dist/physics/exponential/preset.d.mts +17 -0
- package/dist/physics/exponential/preset.mjs +182 -0
- package/dist/physics/gas-process/index.d.mts +1 -0
- package/dist/physics/gas-process/preset.d.mts +30 -0
- package/dist/physics/gas-process/preset.mjs +384 -0
- package/dist/physics/gravitation/index.d.mts +1 -0
- package/dist/physics/gravitation/preset.d.mts +24 -0
- package/dist/physics/gravitation/preset.mjs +345 -0
- package/dist/physics/gravity-drop.d.mts +9 -0
- package/dist/physics/gravity-drop.mjs +187 -0
- package/dist/physics/heat-transfer/index.d.mts +1 -0
- package/dist/physics/heat-transfer/preset.d.mts +27 -0
- package/dist/physics/heat-transfer/preset.mjs +626 -0
- package/dist/physics/impulse/index.d.mts +1 -0
- package/dist/physics/impulse/preset.d.mts +29 -0
- package/dist/physics/impulse/preset.mjs +453 -0
- package/dist/physics/index.d.mts +43 -0
- package/dist/physics/index.mjs +44 -0
- package/dist/physics/kepler/index.d.mts +1 -0
- package/dist/physics/kepler/preset.d.mts +27 -0
- package/dist/physics/kepler/preset.mjs +257 -0
- package/dist/physics/lever/asset.d.mts +6 -0
- package/dist/physics/lever/asset.mjs +220 -0
- package/dist/physics/lever/index.d.mts +2 -0
- package/dist/physics/lever/preset.d.mts +31 -0
- package/dist/physics/lever/preset.mjs +261 -0
- package/dist/physics/lorentz/index.d.mts +1 -0
- package/dist/physics/lorentz/preset.d.mts +29 -0
- package/dist/physics/lorentz/preset.mjs +367 -0
- package/dist/physics/magnetism/index.d.mts +1 -0
- package/dist/physics/magnetism/preset.d.mts +15 -0
- package/dist/physics/magnetism/preset.mjs +334 -0
- package/dist/physics/optics/asset.d.mts +6 -0
- package/dist/physics/optics/asset.mjs +234 -0
- package/dist/physics/optics/index.d.mts +2 -0
- package/dist/physics/optics/preset.d.mts +14 -0
- package/dist/physics/optics/preset.mjs +202 -0
- package/dist/physics/orbit-lab.d.mts +6 -0
- package/dist/physics/orbit-lab.mjs +222 -0
- package/dist/physics/projectile-lab.d.mts +10 -0
- package/dist/physics/projectile-lab.mjs +354 -0
- package/dist/physics/rain-relative/index.d.mts +1 -0
- package/dist/physics/rain-relative/preset.d.mts +19 -0
- package/dist/physics/rain-relative/preset.mjs +358 -0
- package/dist/physics/ramp-forces/index.d.mts +1 -0
- package/dist/physics/ramp-forces/preset.d.mts +36 -0
- package/dist/physics/ramp-forces/preset.mjs +550 -0
- package/dist/physics/river-boat.d.mts +22 -0
- package/dist/physics/river-boat.mjs +498 -0
- package/dist/physics/shm/index.d.mts +1 -0
- package/dist/physics/shm/preset.d.mts +33 -0
- package/dist/physics/shm/preset.mjs +554 -0
- package/dist/physics/stopping-distance/index.d.mts +1 -0
- package/dist/physics/stopping-distance/preset.d.mts +29 -0
- package/dist/physics/stopping-distance/preset.mjs +662 -0
- package/dist/physics/temperature-scales/index.d.mts +1 -0
- package/dist/physics/temperature-scales/preset.d.mts +15 -0
- package/dist/physics/temperature-scales/preset.mjs +353 -0
- package/dist/physics/terminal-velocity/index.d.mts +1 -0
- package/dist/physics/terminal-velocity/preset.d.mts +26 -0
- package/dist/physics/terminal-velocity/preset.mjs +404 -0
- package/dist/physics/thermal/index.d.mts +1 -0
- package/dist/physics/thermal/preset.d.mts +44 -0
- package/dist/physics/thermal/preset.mjs +373 -0
- package/dist/physics/vector-board/index.d.mts +1 -0
- package/dist/physics/vector-board/preset.d.mts +65 -0
- package/dist/physics/vector-board/preset.mjs +273 -0
- package/dist/physics/vector-board/view.d.mts +49 -0
- package/dist/physics/vector-board/view.mjs +58 -0
- package/dist/physics/vector-scene.d.mts +41 -0
- package/dist/physics/vector-scene.mjs +211 -0
- package/dist/physics/vector-types/index.d.mts +1 -0
- package/dist/physics/vector-types/preset.d.mts +27 -0
- package/dist/physics/vector-types/preset.mjs +192 -0
- package/dist/physics/water-density/index.d.mts +1 -0
- package/dist/physics/water-density/preset.d.mts +18 -0
- package/dist/physics/water-density/preset.mjs +439 -0
- package/dist/physics/waves/core.mjs +33 -0
- package/dist/physics/waves/doppler.d.mts +23 -0
- package/dist/physics/waves/doppler.mjs +260 -0
- package/dist/physics/waves/index.d.mts +4 -0
- package/dist/physics/waves/preset.d.mts +30 -0
- package/dist/physics/waves/preset.mjs +488 -0
- package/dist/physics/waves/ripple.d.mts +26 -0
- package/dist/physics/waves/ripple.mjs +234 -0
- package/dist/physics/waves/string.d.mts +29 -0
- package/dist/physics/waves/string.mjs +289 -0
- package/dist/physics/work-energy/index.d.mts +1 -0
- package/dist/physics/work-energy/preset.d.mts +17 -0
- package/dist/physics/work-energy/preset.mjs +341 -0
- package/dist/schemas/index.d.mts +235 -0
- package/dist/schemas/index.mjs +145 -0
- package/dist/statistics/center-spread/preset.d.mts +34 -0
- package/dist/statistics/center-spread/preset.mjs +323 -0
- package/dist/statistics/core/descriptive.d.mts +35 -0
- package/dist/statistics/core/descriptive.mjs +64 -0
- package/dist/statistics/core/normal.d.mts +21 -0
- package/dist/statistics/core/normal.mjs +37 -0
- package/dist/statistics/core/sequences.d.mts +27 -0
- package/dist/statistics/core/sequences.mjs +35 -0
- package/dist/statistics/galton/preset.d.mts +27 -0
- package/dist/statistics/galton/preset.mjs +331 -0
- package/dist/statistics/histogram/preset.d.mts +27 -0
- package/dist/statistics/histogram/preset.mjs +385 -0
- package/dist/statistics/index.d.mts +11 -0
- package/dist/statistics/index.mjs +12 -0
- package/dist/statistics/normal/preset.d.mts +30 -0
- package/dist/statistics/normal/preset.mjs +400 -0
- package/dist/statistics/sampling/preset.d.mts +32 -0
- package/dist/statistics/sampling/preset.mjs +406 -0
- package/dist/statistics/sequence/preset.d.mts +28 -0
- package/dist/statistics/sequence/preset.mjs +302 -0
- package/dist/statistics/z-table/preset.d.mts +28 -0
- package/dist/statistics/z-table/preset.mjs +348 -0
- package/package.json +266 -0
- package/styles.css +267 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { clamp } from "../../core/util.mjs";
|
|
4
|
+
import { CheckButton, Slider, StatusPill } from "../../kit/controls.mjs";
|
|
5
|
+
import { ControlBar, Field, LabFrame, LiveRegion } from "../../kit/frame.mjs";
|
|
6
|
+
import { useCheckpoint } from "../../kit/pedagogy.mjs";
|
|
7
|
+
import { demandQ, equilibrium, supplyQ } from "./core.mjs";
|
|
8
|
+
import { useState } from "react";
|
|
9
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { Axes, Dot, Label, MovableDot, Polygon, Segment, Stage } from "@classytic/stage";
|
|
11
|
+
|
|
12
|
+
//#region src/commerce/economics/market-equilibrium.tsx
|
|
13
|
+
/**
|
|
14
|
+
* MarketEquilibriumLab — Marshall's scissors: where the market clears.
|
|
15
|
+
*
|
|
16
|
+
* Drag a horizontal PRICE line across a fixed demand line + supply line. At any
|
|
17
|
+
* non-equilibrium price the lab shades the HORIZONTAL gap between Qd and Qs —
|
|
18
|
+
* amber SURPLUS above equilibrium (pressure pushes price down), red SHORTAGE
|
|
19
|
+
* below (pressure pushes price up) — and the band collapses to nothing at the
|
|
20
|
+
* crossing, where a green pill reads "market clears, Qd = Qs". Shift sliders move
|
|
21
|
+
* either curve to watch BOTH P* and Q* move. Reuses the shared econ core +
|
|
22
|
+
* Stage primitives; tokenized; reduced-motion safe (no autoplay — the learner drags).
|
|
23
|
+
*
|
|
24
|
+
* The algebra (solve a−bQ = c+dQ for Q*) belongs in a paired MathDerivation.
|
|
25
|
+
*/
|
|
26
|
+
const DEMAND0 = {
|
|
27
|
+
intercept: 9,
|
|
28
|
+
slope: .8
|
|
29
|
+
};
|
|
30
|
+
const SUPPLY0 = {
|
|
31
|
+
intercept: 1,
|
|
32
|
+
slope: .7
|
|
33
|
+
};
|
|
34
|
+
function MarketEquilibriumLab({ demand = DEMAND0, supply = SUPPLY0, shiftControls = {
|
|
35
|
+
demand: true,
|
|
36
|
+
supply: true
|
|
37
|
+
}, priceMax = 10, qtyMax = 12, goodLabel = "the good", title = "Marshall's scissors — where the market clears", prompt = "Drag the price. Above equilibrium → surplus; below → shortage; the gap is Qs − Qd.", height = 320, objectives }) {
|
|
38
|
+
const [dShift, setDShift] = useState(0);
|
|
39
|
+
const [sShift, setSShift] = useState(0);
|
|
40
|
+
const d = {
|
|
41
|
+
intercept: demand.intercept + dShift,
|
|
42
|
+
slope: demand.slope
|
|
43
|
+
};
|
|
44
|
+
const s = {
|
|
45
|
+
intercept: supply.intercept + sShift,
|
|
46
|
+
slope: supply.slope
|
|
47
|
+
};
|
|
48
|
+
const eq = equilibrium(d, s);
|
|
49
|
+
const [price, setPrice] = useState(clamp(eq.p + 2, .4, priceMax - .4));
|
|
50
|
+
const qd = demandQ(d, price);
|
|
51
|
+
const qs = supplyQ(s, price);
|
|
52
|
+
const gap = qs - qd;
|
|
53
|
+
const cleared = Math.abs(gap) < .05;
|
|
54
|
+
const state = cleared ? "cleared" : gap > 0 ? "surplus" : "shortage";
|
|
55
|
+
useCheckpoint({
|
|
56
|
+
solved: cleared,
|
|
57
|
+
activity: "market-equilibrium"
|
|
58
|
+
});
|
|
59
|
+
const view = {
|
|
60
|
+
xMin: -.8,
|
|
61
|
+
xMax: qtyMax + .4,
|
|
62
|
+
yMin: -.8,
|
|
63
|
+
yMax: priceMax + .4
|
|
64
|
+
};
|
|
65
|
+
const dQatP0 = d.intercept / d.slope;
|
|
66
|
+
const sPatQmax = s.intercept + s.slope * qtyMax;
|
|
67
|
+
const bandColor = state === "surplus" ? "var(--stage-warn)" : "var(--stage-danger)";
|
|
68
|
+
const lo = Math.min(qd, qs), hi = Math.max(qd, qs);
|
|
69
|
+
const figure = /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
|
|
70
|
+
style: {
|
|
71
|
+
borderRadius: 14,
|
|
72
|
+
overflow: "hidden",
|
|
73
|
+
background: "var(--stage-bg)",
|
|
74
|
+
border: "1px solid var(--stage-grid)"
|
|
75
|
+
},
|
|
76
|
+
children: /* @__PURE__ */ jsxs(Stage, {
|
|
77
|
+
view,
|
|
78
|
+
height,
|
|
79
|
+
preserveAspect: false,
|
|
80
|
+
ariaLabel: `Supply and demand; price ${price.toFixed(1)}, Qd ${qd.toFixed(1)}, Qs ${qs.toFixed(1)}, ${state}`,
|
|
81
|
+
children: [
|
|
82
|
+
/* @__PURE__ */ jsx(Axes, { ticks: false }),
|
|
83
|
+
/* @__PURE__ */ jsx(Label, {
|
|
84
|
+
x: qtyMax / 2,
|
|
85
|
+
y: -.5,
|
|
86
|
+
text: "Quantity →",
|
|
87
|
+
color: "var(--stage-muted)",
|
|
88
|
+
size: 11
|
|
89
|
+
}),
|
|
90
|
+
/* @__PURE__ */ jsx(Label, {
|
|
91
|
+
x: -.5,
|
|
92
|
+
y: priceMax / 2,
|
|
93
|
+
text: "Price",
|
|
94
|
+
color: "var(--stage-muted)",
|
|
95
|
+
size: 11
|
|
96
|
+
}),
|
|
97
|
+
/* @__PURE__ */ jsx(Segment, {
|
|
98
|
+
from: {
|
|
99
|
+
x: 0,
|
|
100
|
+
y: d.intercept
|
|
101
|
+
},
|
|
102
|
+
to: {
|
|
103
|
+
x: dQatP0,
|
|
104
|
+
y: 0
|
|
105
|
+
},
|
|
106
|
+
color: "var(--stage-accent)",
|
|
107
|
+
weight: 2.5
|
|
108
|
+
}),
|
|
109
|
+
/* @__PURE__ */ jsx(Label, {
|
|
110
|
+
x: dQatP0 * .5,
|
|
111
|
+
y: d.intercept * .5,
|
|
112
|
+
text: "Demand",
|
|
113
|
+
color: "var(--stage-accent)",
|
|
114
|
+
size: 11,
|
|
115
|
+
dx: 14
|
|
116
|
+
}),
|
|
117
|
+
/* @__PURE__ */ jsx(Segment, {
|
|
118
|
+
from: {
|
|
119
|
+
x: 0,
|
|
120
|
+
y: s.intercept
|
|
121
|
+
},
|
|
122
|
+
to: {
|
|
123
|
+
x: qtyMax,
|
|
124
|
+
y: sPatQmax
|
|
125
|
+
},
|
|
126
|
+
color: "var(--stage-accent-2)",
|
|
127
|
+
weight: 2.5
|
|
128
|
+
}),
|
|
129
|
+
/* @__PURE__ */ jsx(Label, {
|
|
130
|
+
x: qtyMax * .7,
|
|
131
|
+
y: s.intercept + s.slope * qtyMax * .7,
|
|
132
|
+
text: "Supply",
|
|
133
|
+
color: "var(--stage-accent-2)",
|
|
134
|
+
size: 11,
|
|
135
|
+
dy: -12
|
|
136
|
+
}),
|
|
137
|
+
!cleared && /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
138
|
+
/* @__PURE__ */ jsx(Segment, {
|
|
139
|
+
from: {
|
|
140
|
+
x: lo,
|
|
141
|
+
y: price
|
|
142
|
+
},
|
|
143
|
+
to: {
|
|
144
|
+
x: hi,
|
|
145
|
+
y: price
|
|
146
|
+
},
|
|
147
|
+
color: bandColor,
|
|
148
|
+
weight: 9,
|
|
149
|
+
opacity: .4
|
|
150
|
+
}),
|
|
151
|
+
/* @__PURE__ */ jsx(Label, {
|
|
152
|
+
x: (lo + hi) / 2,
|
|
153
|
+
y: price,
|
|
154
|
+
text: state === "surplus" ? `SURPLUS ${gap.toFixed(1)}` : `SHORTAGE ${(-gap).toFixed(1)}`,
|
|
155
|
+
color: bandColor,
|
|
156
|
+
size: 11,
|
|
157
|
+
dy: state === "surplus" ? -12 : 14
|
|
158
|
+
}),
|
|
159
|
+
/* @__PURE__ */ jsx(Polygon, {
|
|
160
|
+
points: state === "surplus" ? [
|
|
161
|
+
{
|
|
162
|
+
x: hi + .5,
|
|
163
|
+
y: price - .1
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
x: hi + .9,
|
|
167
|
+
y: price - .1
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
x: hi + .7,
|
|
171
|
+
y: price - .9
|
|
172
|
+
}
|
|
173
|
+
] : [
|
|
174
|
+
{
|
|
175
|
+
x: hi + .5,
|
|
176
|
+
y: price + .1
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
x: hi + .9,
|
|
180
|
+
y: price + .1
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
x: hi + .7,
|
|
184
|
+
y: price + .9
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
color: bandColor,
|
|
188
|
+
fill: bandColor,
|
|
189
|
+
fillOpacity: .8,
|
|
190
|
+
weight: 0
|
|
191
|
+
})
|
|
192
|
+
] }),
|
|
193
|
+
/* @__PURE__ */ jsx(Segment, {
|
|
194
|
+
from: {
|
|
195
|
+
x: eq.q,
|
|
196
|
+
y: 0
|
|
197
|
+
},
|
|
198
|
+
to: {
|
|
199
|
+
x: eq.q,
|
|
200
|
+
y: eq.p
|
|
201
|
+
},
|
|
202
|
+
color: "var(--stage-good)",
|
|
203
|
+
weight: 1,
|
|
204
|
+
dashed: true,
|
|
205
|
+
opacity: .6
|
|
206
|
+
}),
|
|
207
|
+
/* @__PURE__ */ jsx(Segment, {
|
|
208
|
+
from: {
|
|
209
|
+
x: 0,
|
|
210
|
+
y: eq.p
|
|
211
|
+
},
|
|
212
|
+
to: {
|
|
213
|
+
x: eq.q,
|
|
214
|
+
y: eq.p
|
|
215
|
+
},
|
|
216
|
+
color: "var(--stage-good)",
|
|
217
|
+
weight: 1,
|
|
218
|
+
dashed: true,
|
|
219
|
+
opacity: .6
|
|
220
|
+
}),
|
|
221
|
+
/* @__PURE__ */ jsx(Dot, {
|
|
222
|
+
x: eq.q,
|
|
223
|
+
y: eq.p,
|
|
224
|
+
r: cleared ? 8 : 5,
|
|
225
|
+
color: "var(--stage-good)"
|
|
226
|
+
}),
|
|
227
|
+
/* @__PURE__ */ jsx(Label, {
|
|
228
|
+
x: eq.q,
|
|
229
|
+
y: eq.p,
|
|
230
|
+
text: `P* ${eq.p.toFixed(1)}, Q* ${eq.q.toFixed(1)}`,
|
|
231
|
+
color: "var(--stage-good)",
|
|
232
|
+
size: 11,
|
|
233
|
+
dx: 10,
|
|
234
|
+
dy: -10
|
|
235
|
+
}),
|
|
236
|
+
/* @__PURE__ */ jsx(Segment, {
|
|
237
|
+
from: {
|
|
238
|
+
x: 0,
|
|
239
|
+
y: price
|
|
240
|
+
},
|
|
241
|
+
to: {
|
|
242
|
+
x: qtyMax,
|
|
243
|
+
y: price
|
|
244
|
+
},
|
|
245
|
+
color: "var(--stage-fg)",
|
|
246
|
+
weight: 1.5,
|
|
247
|
+
opacity: .5,
|
|
248
|
+
dashed: true
|
|
249
|
+
}),
|
|
250
|
+
/* @__PURE__ */ jsx(MovableDot, {
|
|
251
|
+
value: {
|
|
252
|
+
x: .35,
|
|
253
|
+
y: price
|
|
254
|
+
},
|
|
255
|
+
onMove: (p) => setPrice(clamp(p.y, .4, priceMax - .4)),
|
|
256
|
+
constrain: "vertical",
|
|
257
|
+
range: {
|
|
258
|
+
min: .4,
|
|
259
|
+
max: priceMax - .4
|
|
260
|
+
},
|
|
261
|
+
color: "var(--stage-fg)",
|
|
262
|
+
ariaLabel: "price"
|
|
263
|
+
}),
|
|
264
|
+
/* @__PURE__ */ jsx(Dot, {
|
|
265
|
+
x: qd,
|
|
266
|
+
y: price,
|
|
267
|
+
r: 4,
|
|
268
|
+
color: "var(--stage-accent)"
|
|
269
|
+
}),
|
|
270
|
+
/* @__PURE__ */ jsx(Dot, {
|
|
271
|
+
x: qs,
|
|
272
|
+
y: price,
|
|
273
|
+
r: 4,
|
|
274
|
+
color: "var(--stage-accent-2)"
|
|
275
|
+
})
|
|
276
|
+
]
|
|
277
|
+
})
|
|
278
|
+
}), /* @__PURE__ */ jsx(LiveRegion, { children: `Price ${price.toFixed(1)} for ${goodLabel}. Quantity demanded ${qd.toFixed(1)}, supplied ${qs.toFixed(1)}. ${state}. Equilibrium price ${eq.p.toFixed(1)}, quantity ${eq.q.toFixed(1)}.` })] });
|
|
279
|
+
return /* @__PURE__ */ jsx(LabFrame, {
|
|
280
|
+
title,
|
|
281
|
+
prompt,
|
|
282
|
+
objectives,
|
|
283
|
+
controls: /* @__PURE__ */ jsxs(ControlBar, { children: [
|
|
284
|
+
shiftControls.demand && /* @__PURE__ */ jsx(Field, {
|
|
285
|
+
label: "shift demand",
|
|
286
|
+
children: /* @__PURE__ */ jsx(Slider, {
|
|
287
|
+
value: dShift,
|
|
288
|
+
min: -4,
|
|
289
|
+
max: 4,
|
|
290
|
+
step: .5,
|
|
291
|
+
onChange: setDShift,
|
|
292
|
+
ariaLabel: "shift the demand curve"
|
|
293
|
+
})
|
|
294
|
+
}),
|
|
295
|
+
shiftControls.supply && /* @__PURE__ */ jsx(Field, {
|
|
296
|
+
label: "shift supply",
|
|
297
|
+
children: /* @__PURE__ */ jsx(Slider, {
|
|
298
|
+
value: sShift,
|
|
299
|
+
min: -4,
|
|
300
|
+
max: 4,
|
|
301
|
+
step: .5,
|
|
302
|
+
onChange: setSShift,
|
|
303
|
+
ariaLabel: "shift the supply curve"
|
|
304
|
+
})
|
|
305
|
+
}),
|
|
306
|
+
/* @__PURE__ */ jsx(Field, {
|
|
307
|
+
label: "price",
|
|
308
|
+
value: price.toFixed(1),
|
|
309
|
+
children: /* @__PURE__ */ jsx(CheckButton, {
|
|
310
|
+
onClick: () => setPrice(clamp(eq.p, .4, priceMax - .4)),
|
|
311
|
+
children: "Snap to equilibrium"
|
|
312
|
+
})
|
|
313
|
+
}),
|
|
314
|
+
/* @__PURE__ */ jsx(Field, {
|
|
315
|
+
label: "Qd",
|
|
316
|
+
value: /* @__PURE__ */ jsx("span", {
|
|
317
|
+
style: { color: "var(--stage-accent)" },
|
|
318
|
+
children: qd.toFixed(1)
|
|
319
|
+
}),
|
|
320
|
+
children: /* @__PURE__ */ jsx("span", {})
|
|
321
|
+
}),
|
|
322
|
+
/* @__PURE__ */ jsx(Field, {
|
|
323
|
+
label: "Qs",
|
|
324
|
+
value: /* @__PURE__ */ jsx("span", {
|
|
325
|
+
style: { color: "var(--stage-accent-2)" },
|
|
326
|
+
children: qs.toFixed(1)
|
|
327
|
+
}),
|
|
328
|
+
children: /* @__PURE__ */ jsx("span", {})
|
|
329
|
+
})
|
|
330
|
+
] }),
|
|
331
|
+
footer: /* @__PURE__ */ jsx(StatusPill, {
|
|
332
|
+
ok: cleared,
|
|
333
|
+
children: state === "cleared" ? "Market clears · Qd = Qs ✓" : state === "surplus" ? "Surplus → price pressured DOWN" : "Shortage → price pressured UP"
|
|
334
|
+
}),
|
|
335
|
+
children: figure
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
//#endregion
|
|
340
|
+
export { MarketEquilibriumLab };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Account, AccountCategory, CATEGORY_COLOR, Side, debitsEqualCredits, equationParts, money, normalBalance, statementOf } from "./accounting/core.mjs";
|
|
2
|
+
import { EquationBalanceLab, EquationBalanceProps, Transaction, TxnEffect } from "./accounting/equation-balance.mjs";
|
|
3
|
+
import { JournalPosterLab, JournalPosterProps, JournalTxn } from "./accounting/journal-poster.mjs";
|
|
4
|
+
import { SortAccount, StatementSorterLab, StatementSorterProps } from "./accounting/statement-sorter.mjs";
|
|
5
|
+
import { Curve, demandP, demandQ, equilibrium, pointElasticity, supplyP, supplyQ } from "./economics/core.mjs";
|
|
6
|
+
import { MarketEquilibriumLab, MarketEquilibriumProps } from "./economics/market-equilibrium.mjs";
|
|
7
|
+
import { ElasticityRevenueLab, ElasticityRevenueProps } from "./economics/elasticity-revenue.mjs";
|
|
8
|
+
import { DemandShiftVsMoveLab, DemandShiftVsMoveProps, Shifter } from "./economics/demand-shift-vs-move.mjs";
|
|
9
|
+
export { type Account, type AccountCategory, CATEGORY_COLOR, type Curve, DemandShiftVsMoveLab, type DemandShiftVsMoveProps, ElasticityRevenueLab, type ElasticityRevenueProps, EquationBalanceLab, type EquationBalanceProps, JournalPosterLab, type JournalPosterProps, type JournalTxn, MarketEquilibriumLab, type MarketEquilibriumProps, type Shifter, type Side, type SortAccount, StatementSorterLab, type StatementSorterProps, type Transaction, type TxnEffect, debitsEqualCredits, demandP, demandQ, equationParts, equilibrium, money, normalBalance, pointElasticity, statementOf, supplyP, supplyQ };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CATEGORY_COLOR, debitsEqualCredits, equationParts, money, normalBalance, statementOf } from "./accounting/core.mjs";
|
|
2
|
+
import { EquationBalanceLab } from "./accounting/equation-balance.mjs";
|
|
3
|
+
import { JournalPosterLab } from "./accounting/journal-poster.mjs";
|
|
4
|
+
import { StatementSorterLab } from "./accounting/statement-sorter.mjs";
|
|
5
|
+
import { demandP, demandQ, equilibrium, pointElasticity, supplyP, supplyQ } from "./economics/core.mjs";
|
|
6
|
+
import { MarketEquilibriumLab } from "./economics/market-equilibrium.mjs";
|
|
7
|
+
import { ElasticityRevenueLab } from "./economics/elasticity-revenue.mjs";
|
|
8
|
+
import { DemandShiftVsMoveLab } from "./economics/demand-shift-vs-move.mjs";
|
|
9
|
+
|
|
10
|
+
export { CATEGORY_COLOR, DemandShiftVsMoveLab, ElasticityRevenueLab, EquationBalanceLab, JournalPosterLab, MarketEquilibriumLab, StatementSorterLab, debitsEqualCredits, demandP, demandQ, equationParts, equilibrium, money, normalBalance, pointElasticity, statementOf, supplyP, supplyQ };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/core/easing.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Easing / rate functions — pure `(t in [0,1]) => number`. Ported from manim's
|
|
4
|
+
* `rate_functions` + the standard web set. Shape `alpha` before interpolation.
|
|
5
|
+
*/
|
|
6
|
+
type Easing = (t: number) => number;
|
|
7
|
+
declare const linear: Easing;
|
|
8
|
+
/** Smootherstep (manim's default `smooth`): zero velocity AND accel at the ends. */
|
|
9
|
+
declare const smooth: Easing;
|
|
10
|
+
declare const easeInCubic: Easing;
|
|
11
|
+
declare const easeOutCubic: Easing;
|
|
12
|
+
declare const easeInOut: Easing;
|
|
13
|
+
/** Accelerate from rest (manim `rush_into`). */
|
|
14
|
+
declare const rushInto: Easing;
|
|
15
|
+
/** Decelerate to rest (manim `rush_from`). */
|
|
16
|
+
declare const rushFrom: Easing;
|
|
17
|
+
/** Go to 1 then back to 0 (manim `there_and_back`) — great for pulses. */
|
|
18
|
+
declare const thereAndBack: Easing;
|
|
19
|
+
/** Overshoot then settle. */
|
|
20
|
+
declare const elastic: Easing;
|
|
21
|
+
/** Standard CSS-style cubic-bezier easing factory. */
|
|
22
|
+
declare function cubicBezier(x1: number, y1: number, x2: number, y2: number): Easing;
|
|
23
|
+
/** Squash an easing into the sub-window [a,b] of [0,1] (manim `squish_rate_func`). */
|
|
24
|
+
declare function squish(fn: Easing, a?: number, b?: number): Easing;
|
|
25
|
+
/** Built-in registry — extend with `registerEasing` (see ./registry). */
|
|
26
|
+
declare const EASINGS: Record<string, Easing>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { EASINGS, Easing, cubicBezier, easeInCubic, easeInOut, easeOutCubic, elastic, linear, rushFrom, rushInto, smooth, squish, thereAndBack };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//#region src/core/easing.ts
|
|
2
|
+
const linear = (t) => t;
|
|
3
|
+
/** Smootherstep (manim's default `smooth`): zero velocity AND accel at the ends. */
|
|
4
|
+
const smooth = (t) => {
|
|
5
|
+
const x = Math.min(1, Math.max(0, t));
|
|
6
|
+
return x * x * x * (x * (x * 6 - 15) + 10);
|
|
7
|
+
};
|
|
8
|
+
const easeInCubic = (t) => t * t * t;
|
|
9
|
+
const easeOutCubic = (t) => 1 - (1 - t) ** 3;
|
|
10
|
+
const easeInOut = (t) => t < .5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2;
|
|
11
|
+
/** Accelerate from rest (manim `rush_into`). */
|
|
12
|
+
const rushInto = (t) => 2 * smooth(t / 2);
|
|
13
|
+
/** Decelerate to rest (manim `rush_from`). */
|
|
14
|
+
const rushFrom = (t) => 2 * smooth(t / 2 + .5) - 1;
|
|
15
|
+
/** Go to 1 then back to 0 (manim `there_and_back`) — great for pulses. */
|
|
16
|
+
const thereAndBack = (t) => smooth(t < .5 ? 2 * t : 2 * (1 - t));
|
|
17
|
+
/** Overshoot then settle. */
|
|
18
|
+
const elastic = (t) => {
|
|
19
|
+
if (t === 0 || t === 1) return t;
|
|
20
|
+
const p = .3;
|
|
21
|
+
return 2 ** (-10 * t) * Math.sin((t - p / 4) * (2 * Math.PI) / p) + 1;
|
|
22
|
+
};
|
|
23
|
+
/** Standard CSS-style cubic-bezier easing factory. */
|
|
24
|
+
function cubicBezier(x1, y1, x2, y2) {
|
|
25
|
+
const cx = 3 * x1;
|
|
26
|
+
const bx = 3 * (x2 - x1) - cx;
|
|
27
|
+
const ax = 1 - cx - bx;
|
|
28
|
+
const cy = 3 * y1;
|
|
29
|
+
const by = 3 * (y2 - y1) - cy;
|
|
30
|
+
const ay = 1 - cy - by;
|
|
31
|
+
const fx = (t) => ((ax * t + bx) * t + cx) * t;
|
|
32
|
+
const fy = (t) => ((ay * t + by) * t + cy) * t;
|
|
33
|
+
const dfx = (t) => (3 * ax * t + 2 * bx) * t + cx;
|
|
34
|
+
return (x) => {
|
|
35
|
+
if (x <= 0) return 0;
|
|
36
|
+
if (x >= 1) return 1;
|
|
37
|
+
let t = x;
|
|
38
|
+
for (let i = 0; i < 8; i++) {
|
|
39
|
+
const e = fx(t) - x;
|
|
40
|
+
if (Math.abs(e) < 1e-4) break;
|
|
41
|
+
const d = dfx(t);
|
|
42
|
+
if (Math.abs(d) < 1e-6) break;
|
|
43
|
+
t -= e / d;
|
|
44
|
+
}
|
|
45
|
+
return fy(Math.min(1, Math.max(0, t)));
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Squash an easing into the sub-window [a,b] of [0,1] (manim `squish_rate_func`). */
|
|
49
|
+
function squish(fn, a = .2, b = .8) {
|
|
50
|
+
return (t) => t < a ? 0 : t > b ? 1 : fn((t - a) / (b - a));
|
|
51
|
+
}
|
|
52
|
+
/** Built-in registry — extend with `registerEasing` (see ./registry). */
|
|
53
|
+
const EASINGS = {
|
|
54
|
+
linear,
|
|
55
|
+
smooth,
|
|
56
|
+
easeInCubic,
|
|
57
|
+
easeOutCubic,
|
|
58
|
+
easeInOut,
|
|
59
|
+
rushInto,
|
|
60
|
+
rushFrom,
|
|
61
|
+
thereAndBack,
|
|
62
|
+
elastic
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { EASINGS, cubicBezier, easeInCubic, easeInOut, easeOutCubic, elastic, linear, rushFrom, rushInto, smooth, squish, thereAndBack };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Rng, gaussian, mulberry32, randInt, sample, shuffle } from "./rng.mjs";
|
|
2
|
+
import { approxEq, clamp, cn, lerp, num, remap, toDeg, toRad } from "./util.mjs";
|
|
3
|
+
import { RealFn, derivativeAt, estimateOneSidedLimit, integrate, riemannSum, sampleFunction, secantSlope } from "./numeric.mjs";
|
|
4
|
+
import { Tex } from "./tex.mjs";
|
|
5
|
+
import { RichText } from "../kit/rich.mjs";
|
|
6
|
+
import { EASINGS, Easing, cubicBezier, easeInCubic, easeInOut, easeOutCubic, elastic, linear, rushFrom, rushInto, smooth, squish, thereAndBack } from "./easing.mjs";
|
|
7
|
+
import { SciValue, derive, useSciValue, useValue, value } from "./reactive.mjs";
|
|
8
|
+
import { Keyframe, TweenOptions, TweenState, keyframes, useTween } from "./timeline.mjs";
|
|
9
|
+
import { RichSpan, parseRichText } from "@classytic/stage";
|
|
10
|
+
export { EASINGS, type Easing, type Keyframe, type RealFn, type RichSpan, RichText, type Rng, type SciValue, Tex, type TweenOptions, type TweenState, approxEq, clamp, cn, cubicBezier, derivativeAt, derive, easeInCubic, easeInOut, easeOutCubic, elastic, estimateOneSidedLimit, gaussian, integrate, keyframes, lerp, linear, mulberry32, num, parseRichText, randInt, remap, riemannSum, rushFrom, rushInto, sample, sampleFunction, secantSlope, shuffle, smooth, squish, thereAndBack, toDeg, toRad, useSciValue, useTween, useValue, value };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { approxEq, clamp, cn, lerp, num, remap, toDeg, toRad } from "./util.mjs";
|
|
2
|
+
import { derivativeAt, estimateOneSidedLimit, integrate, riemannSum, sampleFunction, secantSlope } from "./numeric.mjs";
|
|
3
|
+
import { gaussian, mulberry32, randInt, sample, shuffle } from "./rng.mjs";
|
|
4
|
+
import { Tex } from "./tex.mjs";
|
|
5
|
+
import { RichText } from "../kit/rich.mjs";
|
|
6
|
+
import { EASINGS, cubicBezier, easeInCubic, easeInOut, easeOutCubic, elastic, linear, rushFrom, rushInto, smooth, squish, thereAndBack } from "./easing.mjs";
|
|
7
|
+
import { derive, useSciValue, useValue, value } from "./reactive.mjs";
|
|
8
|
+
import { keyframes, useTween } from "./timeline.mjs";
|
|
9
|
+
import { parseRichText } from "@classytic/stage";
|
|
10
|
+
|
|
11
|
+
export { EASINGS, RichText, Tex, approxEq, clamp, cn, cubicBezier, derivativeAt, derive, easeInCubic, easeInOut, easeOutCubic, elastic, estimateOneSidedLimit, gaussian, integrate, keyframes, lerp, linear, mulberry32, num, parseRichText, randInt, remap, riemannSum, rushFrom, rushInto, sample, sampleFunction, secantSlope, shuffle, smooth, squish, thereAndBack, toDeg, toRad, useSciValue, useTween, useValue, value };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/core/numeric.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* numeric — small numerical-calculus helpers, used when an exact symbolic result
|
|
4
|
+
* isn't available (e.g. a function the differentiator doesn't handle) or when a
|
|
5
|
+
* widget just needs a number. Pure, dependency-free.
|
|
6
|
+
*/
|
|
7
|
+
type RealFn = (x: number) => number;
|
|
8
|
+
/** Numerical derivative via the symmetric difference quotient. */
|
|
9
|
+
declare function derivativeAt(fn: RealFn, x: number, h?: number): number;
|
|
10
|
+
/** Slope of the secant line through (a, f(a)) and (b, f(b)). */
|
|
11
|
+
declare function secantSlope(fn: RealFn, a: number, b: number): number;
|
|
12
|
+
/** Sample a function across a range into `{x, y}` points (skips non-finite y is the caller's job). */
|
|
13
|
+
declare function sampleFunction(fn: RealFn, range: [number, number], samples?: number): {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
}[];
|
|
17
|
+
/** Riemann sum of `fn` over `[a, b]` with `n` subintervals. A teaching estimate. */
|
|
18
|
+
declare function riemannSum(fn: RealFn, range: [number, number], n: number, mode?: 'left' | 'right' | 'mid'): number;
|
|
19
|
+
/**
|
|
20
|
+
* Composite Simpson's rule — a high-accuracy definite-integral estimate (error
|
|
21
|
+
* O(h⁴), vs O(h) for a Riemann sum). Used as the "reference" a Riemann sum
|
|
22
|
+
* converges toward. `n` is forced even. Not exact, but accurate to ~machine
|
|
23
|
+
* precision for smooth integrands at n≈1000.
|
|
24
|
+
*/
|
|
25
|
+
declare function integrate(fn: RealFn, range: [number, number], n?: number): number;
|
|
26
|
+
/**
|
|
27
|
+
* Estimate a one-sided limit of `fn` as x → c from `side` (+1 right, −1 left) by
|
|
28
|
+
* sampling a shrinking sequence of offsets. Returns the closest-in value and
|
|
29
|
+
* whether the sequence is *converging* (consecutive samples agree) — so callers
|
|
30
|
+
* can honestly report "estimated limit" + confidence rather than a hard claim.
|
|
31
|
+
*/
|
|
32
|
+
declare function estimateOneSidedLimit(fn: RealFn, c: number, side: 1 | -1): {
|
|
33
|
+
value: number;
|
|
34
|
+
converging: boolean;
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { RealFn, derivativeAt, estimateOneSidedLimit, integrate, riemannSum, sampleFunction, secantSlope };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//#region src/core/numeric.ts
|
|
2
|
+
/** Numerical derivative via the symmetric difference quotient. */
|
|
3
|
+
function derivativeAt(fn, x, h = 1e-5) {
|
|
4
|
+
return (fn(x + h) - fn(x - h)) / (2 * h);
|
|
5
|
+
}
|
|
6
|
+
/** Slope of the secant line through (a, f(a)) and (b, f(b)). */
|
|
7
|
+
function secantSlope(fn, a, b) {
|
|
8
|
+
return (fn(b) - fn(a)) / (b - a);
|
|
9
|
+
}
|
|
10
|
+
/** Sample a function across a range into `{x, y}` points (skips non-finite y is the caller's job). */
|
|
11
|
+
function sampleFunction(fn, range, samples = 200) {
|
|
12
|
+
const [min, max] = range;
|
|
13
|
+
const out = [];
|
|
14
|
+
for (let i = 0; i <= samples; i++) {
|
|
15
|
+
const x = min + (max - min) * i / samples;
|
|
16
|
+
out.push({
|
|
17
|
+
x,
|
|
18
|
+
y: fn(x)
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
/** Riemann sum of `fn` over `[a, b]` with `n` subintervals. A teaching estimate. */
|
|
24
|
+
function riemannSum(fn, range, n, mode = "mid") {
|
|
25
|
+
const [a, b] = range;
|
|
26
|
+
const dx = (b - a) / n;
|
|
27
|
+
let sum = 0;
|
|
28
|
+
for (let i = 0; i < n; i++) {
|
|
29
|
+
const x = mode === "left" ? a + i * dx : mode === "right" ? a + (i + 1) * dx : a + (i + .5) * dx;
|
|
30
|
+
sum += fn(x);
|
|
31
|
+
}
|
|
32
|
+
return sum * dx;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Composite Simpson's rule — a high-accuracy definite-integral estimate (error
|
|
36
|
+
* O(h⁴), vs O(h) for a Riemann sum). Used as the "reference" a Riemann sum
|
|
37
|
+
* converges toward. `n` is forced even. Not exact, but accurate to ~machine
|
|
38
|
+
* precision for smooth integrands at n≈1000.
|
|
39
|
+
*/
|
|
40
|
+
function integrate(fn, range, n = 1e3) {
|
|
41
|
+
const [a, b] = range;
|
|
42
|
+
const m = Math.max(2, Math.ceil(n / 2) * 2);
|
|
43
|
+
const h = (b - a) / m;
|
|
44
|
+
let sum = fn(a) + fn(b);
|
|
45
|
+
for (let i = 1; i < m; i++) sum += (i % 2 === 1 ? 4 : 2) * fn(a + i * h);
|
|
46
|
+
return sum * h / 3;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Estimate a one-sided limit of `fn` as x → c from `side` (+1 right, −1 left) by
|
|
50
|
+
* sampling a shrinking sequence of offsets. Returns the closest-in value and
|
|
51
|
+
* whether the sequence is *converging* (consecutive samples agree) — so callers
|
|
52
|
+
* can honestly report "estimated limit" + confidence rather than a hard claim.
|
|
53
|
+
*/
|
|
54
|
+
function estimateOneSidedLimit(fn, c, side) {
|
|
55
|
+
const vals = [
|
|
56
|
+
.1,
|
|
57
|
+
.01,
|
|
58
|
+
.001,
|
|
59
|
+
1e-4,
|
|
60
|
+
1e-5
|
|
61
|
+
].map((h) => fn(c + side * h)).filter((v) => Number.isFinite(v));
|
|
62
|
+
if (vals.length < 2) return {
|
|
63
|
+
value: NaN,
|
|
64
|
+
converging: false
|
|
65
|
+
};
|
|
66
|
+
const last = vals[vals.length - 1];
|
|
67
|
+
const prev = vals[vals.length - 2];
|
|
68
|
+
return {
|
|
69
|
+
value: last,
|
|
70
|
+
converging: Math.abs(last - prev) < .01 * (1 + Math.abs(last))
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { derivativeAt, estimateOneSidedLimit, integrate, riemannSum, sampleFunction, secantSlope };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/core/reactive.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Tiny reactive value — the `ValueTracker` / signal at the heart of
|
|
4
|
+
* interactivity. A slider/drag updates a `value()`; anything derived from it
|
|
5
|
+
* recomputes; React components bound via `useValue` repaint. Framework-light
|
|
6
|
+
* (no external dep); the React glue is one hook.
|
|
7
|
+
*/
|
|
8
|
+
interface SciValue<T> {
|
|
9
|
+
get(): T;
|
|
10
|
+
set(next: T): void;
|
|
11
|
+
/** Functional update. */
|
|
12
|
+
update(fn: (prev: T) => T): void;
|
|
13
|
+
subscribe(fn: (v: T) => void): () => void;
|
|
14
|
+
readonly isSciValue: true;
|
|
15
|
+
}
|
|
16
|
+
declare function value<T>(initial: T): SciValue<T>;
|
|
17
|
+
/** Read-only computed value derived from one or more `SciValue`s. */
|
|
18
|
+
declare function derive<T>(deps: ReadonlyArray<SciValue<unknown>>, compute: () => T): SciValue<T>;
|
|
19
|
+
/** Subscribe a React component to a `SciValue`; returns its current value. */
|
|
20
|
+
declare function useValue<T>(sv: SciValue<T>): T;
|
|
21
|
+
/** Create a stable `SciValue` that lives for the component's lifetime. */
|
|
22
|
+
declare function useSciValue<T>(initial: T | (() => T)): SciValue<T>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { SciValue, derive, useSciValue, useValue, value };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useEffect, useReducer, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/core/reactive.ts
|
|
4
|
+
/**
|
|
5
|
+
* Tiny reactive value — the `ValueTracker` / signal at the heart of
|
|
6
|
+
* interactivity. A slider/drag updates a `value()`; anything derived from it
|
|
7
|
+
* recomputes; React components bound via `useValue` repaint. Framework-light
|
|
8
|
+
* (no external dep); the React glue is one hook.
|
|
9
|
+
*/
|
|
10
|
+
function value(initial) {
|
|
11
|
+
let current = initial;
|
|
12
|
+
const subs = /* @__PURE__ */ new Set();
|
|
13
|
+
const sv = {
|
|
14
|
+
isSciValue: true,
|
|
15
|
+
get: () => current,
|
|
16
|
+
set: (next) => {
|
|
17
|
+
if (Object.is(next, current)) return;
|
|
18
|
+
current = next;
|
|
19
|
+
for (const fn of subs) fn(current);
|
|
20
|
+
},
|
|
21
|
+
update: (fn) => sv.set(fn(current)),
|
|
22
|
+
subscribe: (fn) => {
|
|
23
|
+
subs.add(fn);
|
|
24
|
+
return () => subs.delete(fn);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return sv;
|
|
28
|
+
}
|
|
29
|
+
/** Read-only computed value derived from one or more `SciValue`s. */
|
|
30
|
+
function derive(deps, compute) {
|
|
31
|
+
const out = value(compute());
|
|
32
|
+
for (const dep of deps) dep.subscribe(() => out.set(compute()));
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
/** Subscribe a React component to a `SciValue`; returns its current value. */
|
|
36
|
+
function useValue(sv) {
|
|
37
|
+
const [, force] = useReducer((c) => c + 1, 0);
|
|
38
|
+
const ref = useRef(sv);
|
|
39
|
+
ref.current = sv;
|
|
40
|
+
useEffect(() => sv.subscribe(() => force()), [sv]);
|
|
41
|
+
return sv.get();
|
|
42
|
+
}
|
|
43
|
+
/** Create a stable `SciValue` that lives for the component's lifetime. */
|
|
44
|
+
function useSciValue(initial) {
|
|
45
|
+
const ref = useRef(null);
|
|
46
|
+
if (ref.current === null) ref.current = value(typeof initial === "function" ? initial() : initial);
|
|
47
|
+
return ref.current;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { derive, useSciValue, useValue, value };
|