@classytic/labs 0.1.0 → 0.2.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/dist/_virtual/_rolldown/runtime.mjs +18 -0
- package/dist/biology/enzyme-rate/preset.mjs +5 -5
- package/dist/biology/genetic-cross/core.d.mts +7 -7
- package/dist/biology/genetic-cross/core.mjs +4 -4
- package/dist/biology/genetic-cross/grid.mjs +132 -123
- package/dist/biology/genetic-cross/preset.mjs +4 -4
- package/dist/biology/genetic-cross/sex-linked.mjs +7 -7
- package/dist/biology/photosynthesis-factors/preset.mjs +8 -8
- package/dist/biology/respiration/preset.mjs +4 -4
- package/dist/biology/sequence/central-dogma.mjs +5 -5
- package/dist/biology/sequence/core.d.mts +6 -6
- package/dist/biology/sequence/core.mjs +1 -1
- package/dist/biology/sequence/preset.mjs +6 -6
- package/dist/blocks/authoring.mjs +5 -5
- package/dist/blocks/biology.d.mts +2 -2
- package/dist/blocks/biology.mjs +5 -5
- package/dist/blocks/chem.d.mts +2 -2
- package/dist/blocks/chem.mjs +13 -13
- package/dist/blocks/circuits.d.mts +293 -4
- package/dist/blocks/circuits.mjs +874 -9
- package/dist/blocks/discrete.d.mts +30 -2
- package/dist/blocks/discrete.mjs +74 -4
- package/dist/blocks/economics.mjs +1 -1
- package/dist/blocks/geography.mjs +1 -1
- package/dist/blocks/geometry.mjs +3 -3
- package/dist/blocks/ict.d.mts +90 -1
- package/dist/blocks/ict.mjs +217 -7
- package/dist/blocks/index.d.mts +3064 -657
- package/dist/blocks/index.mjs +9 -9
- package/dist/blocks/lab-block.mjs +5 -5
- package/dist/blocks/lab-config.d.mts +1 -1
- package/dist/blocks/lab-config.mjs +4 -4
- package/dist/blocks/lab-gallery.d.mts +1 -1
- package/dist/blocks/lab-gallery.mjs +2 -2
- package/dist/blocks/language.d.mts +6 -6
- package/dist/blocks/language.mjs +12 -12
- package/dist/blocks/lesson.mjs +4 -4
- package/dist/blocks/math.d.mts +577 -11
- package/dist/blocks/math.mjs +1648 -14
- package/dist/blocks/ml.d.mts +45 -1
- package/dist/blocks/ml.mjs +80 -6
- package/dist/blocks/physics.d.mts +9 -4
- package/dist/blocks/physics.mjs +75 -28
- package/dist/blocks/statistics.mjs +1 -1
- package/dist/build/CircuitEditor.d.mts +14 -0
- package/dist/build/CircuitEditor.mjs +787 -0
- package/dist/build/CircuitPlayer.d.mts +19 -0
- package/dist/build/CircuitPlayer.mjs +53 -0
- package/dist/build/CircuitScene.d.mts +61 -0
- package/dist/build/CircuitScene.mjs +383 -0
- package/dist/build/contract.d.mts +116 -0
- package/dist/build/editor-ops.d.mts +65 -0
- package/dist/build/editor-ops.mjs +306 -0
- package/dist/build/editor-ui.mjs +121 -0
- package/dist/build/flow.d.mts +14 -0
- package/dist/build/flow.mjs +119 -0
- package/dist/build/index.d.mts +10 -0
- package/dist/build/index.mjs +10 -0
- package/dist/build/parts/ammeter.d.mts +1 -0
- package/dist/build/parts/ammeter.mjs +32 -0
- package/dist/build/parts/bulb.d.mts +1 -0
- package/dist/build/parts/bulb.mjs +50 -0
- package/dist/build/parts/capacitor.d.mts +1 -0
- package/dist/build/parts/capacitor.mjs +26 -0
- package/dist/build/parts/cell.d.mts +1 -0
- package/dist/build/parts/cell.mjs +40 -0
- package/dist/build/parts/diode.d.mts +1 -0
- package/dist/build/parts/diode.mjs +33 -0
- package/dist/build/parts/index.d.mts +5 -0
- package/dist/build/parts/index.mjs +43 -0
- package/dist/build/parts/mosfet.d.mts +1 -0
- package/dist/build/parts/mosfet.mjs +95 -0
- package/dist/build/parts/node.d.mts +1 -0
- package/dist/build/parts/node.mjs +32 -0
- package/dist/build/parts/resistor.d.mts +1 -0
- package/dist/build/parts/resistor.mjs +49 -0
- package/dist/build/parts/shared.mjs +42 -0
- package/dist/build/parts/switch.d.mts +1 -0
- package/dist/build/parts/switch.mjs +34 -0
- package/dist/build/parts.d.mts +1 -0
- package/dist/build/registry.d.mts +9 -0
- package/dist/build/registry.mjs +15 -0
- package/dist/build/solve.d.mts +8 -0
- package/dist/build/solve.mjs +0 -0
- package/dist/catalog/registry.d.mts +2 -2
- package/dist/catalog/templates.d.mts +1 -1
- package/dist/catalog/templates.mjs +6 -6
- package/dist/chem/battery.mjs +1 -1
- package/dist/chem/bohr-atom.mjs +4 -4
- package/dist/chem/diffusion/preset.mjs +4 -4
- package/dist/chem/electrochem/preset.mjs +5 -5
- package/dist/chem/equilibrium/preset.d.mts +1 -1
- package/dist/chem/equilibrium/preset.mjs +6 -6
- package/dist/chem/gas-box/preset.mjs +6 -6
- package/dist/chem/kinetics/preset.mjs +6 -6
- package/dist/chem/periodic-trends/preset.mjs +7 -7
- package/dist/chem/reaction-lab.mjs +3 -3
- package/dist/chem/reaction-profile.mjs +4 -4
- package/dist/chem/solution/dilution.mjs +6 -6
- package/dist/chem/solution/field.d.mts +2 -2
- package/dist/chem/solution/field.mjs +2 -2
- package/dist/chem/solution/solution-box.mjs +7 -7
- package/dist/chem/stoichiometry/preset.mjs +5 -5
- package/dist/chem/titration/preset.mjs +5 -5
- package/dist/circuits/ac-dc/asset.mjs +1 -1
- package/dist/circuits/ac-dc/preset.mjs +2 -2
- package/dist/circuits/brownout/index.d.mts +1 -0
- package/dist/circuits/brownout/preset.d.mts +22 -0
- package/dist/circuits/brownout/preset.mjs +399 -0
- package/dist/circuits/capacitor-leak/preset.mjs +13 -8
- package/dist/circuits/circuit/asset.mjs +71 -14
- package/dist/circuits/circuit/preset.mjs +23 -5
- package/dist/circuits/circuit-builder.mjs +60 -132
- package/dist/circuits/circuit-lab.mjs +60 -40
- package/dist/circuits/cmos-gate/index.d.mts +1 -0
- package/dist/circuits/cmos-gate/preset.d.mts +75 -0
- package/dist/circuits/cmos-gate/preset.mjs +1491 -0
- package/dist/circuits/diode/index.d.mts +1 -0
- package/dist/circuits/diode/preset.d.mts +25 -0
- package/dist/circuits/diode/preset.mjs +266 -0
- package/dist/circuits/index.d.mts +7 -1
- package/dist/circuits/index.mjs +7 -1
- package/dist/circuits/rc-charging/index.d.mts +1 -0
- package/dist/circuits/rc-charging/preset.d.mts +27 -0
- package/dist/circuits/rc-charging/preset.mjs +329 -0
- package/dist/circuits/semiconductor/index.d.mts +1 -0
- package/dist/circuits/semiconductor/preset.d.mts +102 -0
- package/dist/circuits/semiconductor/preset.mjs +1855 -0
- package/dist/circuits/transistor/index.d.mts +1 -0
- package/dist/circuits/transistor/preset.d.mts +27 -0
- package/dist/circuits/transistor/preset.mjs +329 -0
- package/dist/commerce/accounting/core.d.mts +1 -1
- package/dist/commerce/accounting/equation-balance.mjs +5 -5
- package/dist/commerce/accounting/journal-poster.mjs +8 -8
- package/dist/commerce/accounting/statement-sorter.mjs +4 -4
- package/dist/commerce/economics/core.d.mts +2 -2
- package/dist/commerce/economics/core.mjs +1 -1
- package/dist/commerce/economics/demand-shift-vs-move.mjs +6 -6
- package/dist/commerce/economics/elasticity-revenue.mjs +6 -6
- package/dist/commerce/economics/market-equilibrium.mjs +5 -5
- package/dist/core/easing.d.mts +3 -3
- package/dist/core/easing.mjs +2 -2
- package/dist/core/numeric.d.mts +3 -3
- package/dist/core/numeric.mjs +2 -2
- package/dist/core/reactive.d.mts +1 -1
- package/dist/core/reactive.mjs +1 -1
- package/dist/core/rng.d.mts +2 -2
- package/dist/core/rng.mjs +1 -1
- package/dist/core/tex.mjs +2 -2
- package/dist/core/timeline.d.mts +1 -1
- package/dist/core/timeline.mjs +1 -1
- package/dist/core/util.mjs +11 -1
- package/dist/discrete/arrangements/preset.mjs +6 -14
- package/dist/discrete/bayes/preset.mjs +43 -35
- package/dist/discrete/binomial/preset.mjs +2 -2
- package/dist/discrete/combination-studio/figure.d.mts +6 -0
- package/dist/discrete/combination-studio/figure.mjs +159 -0
- package/dist/discrete/combination-studio/index.d.mts +2 -0
- package/dist/discrete/combination-studio/preset.d.mts +44 -0
- package/dist/discrete/combination-studio/preset.mjs +440 -0
- package/dist/discrete/core/combinatorics.d.mts +23 -3
- package/dist/discrete/core/combinatorics.mjs +38 -3
- package/dist/discrete/core/pigeonhole.d.mts +1 -1
- package/dist/discrete/core/pigeonhole.mjs +1 -1
- package/dist/discrete/core/probability.d.mts +3 -3
- package/dist/discrete/core/probability.mjs +3 -3
- package/dist/discrete/core/sets.d.mts +1 -1
- package/dist/discrete/counting-slots/preset.mjs +8 -8
- package/dist/discrete/counting-tree/preset.mjs +65 -8
- package/dist/discrete/expected-value/preset.mjs +13 -13
- package/dist/discrete/hypergeometric/preset.mjs +48 -15
- package/dist/discrete/index.d.mts +4 -2
- package/dist/discrete/index.mjs +4 -2
- package/dist/discrete/karnaugh/preset.mjs +26 -20
- package/dist/discrete/lln/preset.mjs +44 -3
- package/dist/discrete/logic-circuit/preset.mjs +2 -2
- package/dist/discrete/monte-carlo/preset.d.mts +1 -1
- package/dist/discrete/monte-carlo/preset.mjs +14 -14
- package/dist/discrete/monty-hall/preset.mjs +6 -6
- package/dist/discrete/outcome-builder/preset.mjs +3 -3
- package/dist/discrete/pascal/preset.mjs +37 -7
- package/dist/discrete/rules.d.mts +20 -0
- package/dist/discrete/rules.mjs +264 -0
- package/dist/discrete/sample-space/preset.mjs +4 -4
- package/dist/discrete/selection/preset.mjs +7 -13
- package/dist/discrete/truth-table/preset.mjs +32 -9
- package/dist/discrete/venn/preset.mjs +71 -48
- package/dist/geography/cycle-lab/preset.mjs +17 -10
- package/dist/geography/cycles.d.mts +3 -3
- package/dist/geography/cycles.mjs +3 -3
- package/dist/geometry/board/preset.d.mts +2 -0
- package/dist/geometry/board/preset.mjs +11 -15
- package/dist/geometry/builder.mjs +3 -3
- package/dist/ict/number-systems/base-odometer.mjs +4 -4
- package/dist/ict/number-systems/bit-grouper.d.mts +1 -1
- package/dist/ict/number-systems/bit-grouper.mjs +4 -4
- package/dist/ict/number-systems/place-value-dial.d.mts +1 -1
- package/dist/ict/number-systems/place-value-dial.mjs +3 -3
- package/dist/ict/number-systems/wheel.d.mts +3 -3
- package/dist/ict/number-systems/wheel.mjs +4 -4
- package/dist/kit/annotate.mjs +3 -3
- package/dist/kit/answer-check.d.mts +2 -2
- package/dist/kit/answer-check.mjs +34 -6
- package/dist/kit/ask.d.mts +19 -0
- package/dist/kit/ask.mjs +46 -0
- package/dist/kit/bar-strip.mjs +53 -0
- package/dist/kit/calc.d.mts +33 -0
- package/dist/kit/calc.mjs +27 -0
- package/dist/kit/carrier-engine.mjs +147 -0
- package/dist/kit/clue-scene.d.mts +86 -0
- package/dist/kit/clue-scene.mjs +424 -0
- package/dist/kit/cluster.d.mts +30 -0
- package/dist/kit/cluster.mjs +81 -0
- package/dist/kit/controls.mjs +11 -5
- package/dist/kit/coords.d.mts +88 -0
- package/dist/kit/coords.mjs +192 -0
- package/dist/kit/data-scene.d.mts +27 -0
- package/dist/kit/data-scene.mjs +199 -0
- package/dist/kit/diagram.mjs +111 -50
- package/dist/kit/electronics.mjs +552 -60
- package/dist/kit/expr-analysis.d.mts +18 -6
- package/dist/kit/expr-analysis.mjs +82 -28
- package/dist/kit/frame.d.mts +3 -3
- package/dist/kit/frame.mjs +25 -6
- package/dist/kit/gameshow.mjs +2 -2
- package/dist/kit/index.d.mts +14 -2
- package/dist/kit/index.mjs +13 -1
- package/dist/kit/logic-gates.mjs +246 -47
- package/dist/kit/palette.mjs +26 -0
- package/dist/kit/pedagogy.d.mts +4 -4
- package/dist/kit/pedagogy.mjs +21 -17
- package/dist/kit/play.d.mts +1 -1
- package/dist/kit/play.mjs +3 -3
- package/dist/kit/predict.d.mts +55 -0
- package/dist/kit/predict.mjs +146 -0
- package/dist/kit/receipt.d.mts +29 -0
- package/dist/kit/receipt.mjs +94 -0
- package/dist/kit/rich.mjs +2 -2
- package/dist/kit/rule.d.mts +59 -0
- package/dist/kit/rule.mjs +215 -0
- package/dist/kit/scale.mjs +1 -1
- package/dist/kit/scene-library.d.mts +22 -0
- package/dist/kit/scene-library.mjs +311 -0
- package/dist/kit/scene-studio.d.mts +14 -0
- package/dist/kit/scene-studio.mjs +338 -0
- package/dist/kit/scenes.d.mts +31 -0
- package/dist/kit/scenes.mjs +569 -0
- package/dist/kit/slot-fill.d.mts +61 -0
- package/dist/kit/slot-fill.mjs +207 -0
- package/dist/kit/solve.d.mts +21 -0
- package/dist/kit/solve.mjs +75 -0
- package/dist/kit/space.mjs +5 -5
- package/dist/kit/steps.mjs +2 -2
- package/dist/kit/vessel.d.mts +69 -0
- package/dist/kit/vessel.mjs +191 -0
- package/dist/language/agreement/preset.mjs +2 -2
- package/dist/language/article-lens/preset.d.mts +1 -1
- package/dist/language/article-lens/preset.mjs +8 -8
- package/dist/language/deck.d.mts +3 -3
- package/dist/language/deck.mjs +1 -1
- package/dist/language/preposition-scene/preset.d.mts +2 -2
- package/dist/language/preposition-scene/preset.mjs +5 -5
- package/dist/language/sentence-builder/preset.mjs +5 -5
- package/dist/language/transform/preset.d.mts +2 -2
- package/dist/language/transform/preset.mjs +5 -5
- package/dist/language/ui.d.mts +3 -3
- package/dist/language/ui.mjs +4 -4
- package/dist/language/word-match/preset.mjs +3 -3
- package/dist/logic/LogicBuildLab.d.mts +22 -0
- package/dist/logic/LogicBuildLab.mjs +170 -0
- package/dist/logic/LogicEditScene.d.mts +31 -0
- package/dist/logic/LogicEditScene.mjs +276 -0
- package/dist/logic/LogicEditor.d.mts +14 -0
- package/dist/logic/LogicEditor.mjs +413 -0
- package/dist/logic/LogicScene.d.mts +32 -0
- package/dist/logic/LogicScene.mjs +277 -0
- package/dist/logic/contract.d.mts +72 -0
- package/dist/logic/display.d.mts +24 -0
- package/dist/logic/display.mjs +127 -0
- package/dist/logic/edit-ops.d.mts +44 -0
- package/dist/logic/edit-ops.mjs +177 -0
- package/dist/logic/evaluate.d.mts +11 -0
- package/dist/logic/evaluate.mjs +93 -0
- package/dist/logic/gates.d.mts +10 -0
- package/dist/logic/gates.mjs +73 -0
- package/dist/logic/index.d.mts +14 -0
- package/dist/logic/index.mjs +13 -0
- package/dist/logic/lab.d.mts +32 -0
- package/dist/logic/lab.mjs +160 -0
- package/dist/logic/presets.d.mts +12 -0
- package/dist/logic/presets.mjs +241 -0
- package/dist/logic/registry.d.mts +9 -0
- package/dist/logic/registry.mjs +15 -0
- package/dist/math/area-model/preset.mjs +70 -44
- package/dist/math/balance-algebra/preset.mjs +14 -5
- package/dist/math/broken-tree/index.d.mts +1 -0
- package/dist/math/broken-tree/preset.d.mts +26 -0
- package/dist/math/broken-tree/preset.mjs +435 -0
- package/dist/math/circle/index.d.mts +1 -0
- package/dist/math/circle/preset.d.mts +44 -0
- package/dist/math/circle/preset.mjs +198 -0
- package/dist/math/complex/core.d.mts +93 -0
- package/dist/math/complex/core.mjs +239 -0
- package/dist/math/complex/index.d.mts +3 -0
- package/dist/math/complex/preset.d.mts +31 -0
- package/dist/math/complex/preset.mjs +377 -0
- package/dist/math/complex/rules.d.mts +6 -0
- package/dist/math/complex/rules.mjs +121 -0
- package/dist/math/conic/index.d.mts +1 -0
- package/dist/math/conic/preset.d.mts +30 -0
- package/dist/math/conic/preset.mjs +334 -0
- package/dist/math/derivation.mjs +5 -5
- package/dist/math/derivative-explorer/preset.mjs +5 -5
- package/dist/math/domain-range/index.d.mts +1 -0
- package/dist/math/domain-range/preset.d.mts +33 -0
- package/dist/math/domain-range/preset.mjs +313 -0
- package/dist/math/fraction-bar/index.d.mts +1 -0
- package/dist/math/fraction-bar/preset.d.mts +27 -0
- package/dist/math/fraction-bar/preset.mjs +197 -0
- package/dist/math/function-machine/preset.mjs +2 -2
- package/dist/math/gradient-descent.mjs +6 -6
- package/dist/math/grapher/preset.d.mts +1 -1
- package/dist/math/grapher/preset.mjs +4 -4
- package/dist/math/harmonic-form/preset.mjs +6 -6
- package/dist/math/index.d.mts +27 -2
- package/dist/math/index.mjs +27 -2
- package/dist/math/integral-explorer/preset.mjs +2 -2
- package/dist/math/interactive/preset.mjs +3 -3
- package/dist/math/limit-explorer/preset.mjs +4 -4
- package/dist/math/linear-model/index.d.mts +1 -0
- package/dist/math/linear-model/preset.d.mts +53 -0
- package/dist/math/linear-model/preset.mjs +164 -0
- package/dist/math/linear-system/preset.mjs +4 -4
- package/dist/math/mystery-bucket/preset.mjs +6 -6
- package/dist/math/number-line/preset.mjs +3 -2
- package/dist/math/parabola/preset.mjs +4 -3
- package/dist/math/pattern/preset.mjs +7 -13
- package/dist/math/percent-bar/index.d.mts +1 -0
- package/dist/math/percent-bar/preset.d.mts +37 -0
- package/dist/math/percent-bar/preset.mjs +275 -0
- package/dist/math/poly/core.d.mts +50 -0
- package/dist/math/poly/core.mjs +268 -0
- package/dist/math/poly/index.d.mts +3 -0
- package/dist/math/poly/preset.d.mts +23 -0
- package/dist/math/poly/preset.mjs +141 -0
- package/dist/math/poly/steps.d.mts +10 -0
- package/dist/math/poly/steps.mjs +99 -0
- package/dist/math/rate-machine/index.d.mts +1 -0
- package/dist/math/rate-machine/preset.d.mts +35 -0
- package/dist/math/rate-machine/preset.mjs +281 -0
- package/dist/math/ratio-share/index.d.mts +1 -0
- package/dist/math/ratio-share/preset.d.mts +24 -0
- package/dist/math/ratio-share/preset.mjs +204 -0
- package/dist/math/receipt/index.d.mts +1 -0
- package/dist/math/receipt/preset.d.mts +22 -0
- package/dist/math/receipt/preset.mjs +137 -0
- package/dist/math/sequence-predict/index.d.mts +1 -0
- package/dist/math/sequence-predict/preset.d.mts +34 -0
- package/dist/math/sequence-predict/preset.mjs +130 -0
- package/dist/math/straight-line/index.d.mts +1 -0
- package/dist/math/straight-line/preset.d.mts +37 -0
- package/dist/math/straight-line/preset.mjs +374 -0
- package/dist/math/system-solve/index.d.mts +1 -0
- package/dist/math/system-solve/preset.d.mts +21 -0
- package/dist/math/system-solve/preset.mjs +227 -0
- package/dist/math/transform/index.d.mts +1 -0
- package/dist/math/transform/preset.d.mts +41 -0
- package/dist/math/transform/preset.mjs +343 -0
- package/dist/math/triangle-trig/preset.mjs +12 -9
- package/dist/math/trig/core.d.mts +37 -0
- package/dist/math/trig/core.mjs +150 -0
- package/dist/math/trig/diagrams.d.mts +1 -0
- package/dist/math/trig/diagrams.mjs +321 -0
- package/dist/math/trig/index.d.mts +3 -0
- package/dist/math/trig/preset.d.mts +25 -0
- package/dist/math/trig/preset.mjs +260 -0
- package/dist/math/trig/rules.d.mts +6 -0
- package/dist/math/trig/rules.mjs +159 -0
- package/dist/math/trig-explorer.mjs +4 -4
- package/dist/ml/boundary/preset.mjs +8 -3
- package/dist/ml/classifier/preset.mjs +31 -6
- package/dist/ml/kmeans/preset.mjs +4 -4
- package/dist/ml/knn/preset.mjs +47 -12
- package/dist/ml/regression/preset.mjs +36 -7
- package/dist/physics/atwood/preset.mjs +4 -4
- package/dist/physics/bullet-walls/preset.d.mts +1 -1
- package/dist/physics/bullet-walls/preset.mjs +7 -7
- package/dist/physics/carnot/preset.mjs +6 -6
- package/dist/physics/circular-motion/preset.mjs +36 -5
- package/dist/physics/collision-track/preset.mjs +35 -5
- package/dist/physics/efficiency/preset.d.mts +2 -2
- package/dist/physics/efficiency/preset.mjs +5 -5
- package/dist/physics/electric-field/preset.mjs +32 -23
- package/dist/physics/electric-flux/index.d.mts +1 -0
- package/dist/physics/electric-flux/preset.d.mts +29 -0
- package/dist/physics/electric-flux/preset.mjs +264 -0
- package/dist/physics/energy-skate/preset.mjs +5 -5
- package/dist/physics/entropy/preset.mjs +7 -7
- package/dist/physics/expansion/preset.mjs +13 -13
- package/dist/physics/exponential/asset.mjs +1 -1
- package/dist/physics/exponential/preset.mjs +4 -4
- package/dist/physics/gas-process/preset.mjs +3 -3
- package/dist/physics/gauss-law/index.d.mts +1 -0
- package/dist/physics/gauss-law/preset.d.mts +20 -0
- package/dist/physics/gauss-law/preset.mjs +286 -0
- package/dist/physics/gravitation/preset.mjs +7 -7
- package/dist/physics/gravity-drop.mjs +4 -4
- package/dist/physics/heat-transfer/preset.d.mts +1 -1
- package/dist/physics/heat-transfer/preset.mjs +10 -10
- package/dist/physics/impulse/preset.mjs +5 -5
- package/dist/physics/index.d.mts +4 -1
- package/dist/physics/index.mjs +4 -1
- package/dist/physics/kepler/preset.mjs +4 -4
- package/dist/physics/lever/preset.mjs +3 -3
- package/dist/physics/lorentz/preset.mjs +11 -11
- package/dist/physics/magnetism/preset.mjs +3 -3
- package/dist/physics/optics/preset.mjs +2 -2
- package/dist/physics/orbit-lab.mjs +5 -5
- package/dist/physics/projectile-lab.mjs +4 -4
- package/dist/physics/rain-relative/preset.mjs +5 -5
- package/dist/physics/ramp-forces/preset.mjs +5 -5
- package/dist/physics/river-boat.mjs +6 -6
- package/dist/physics/shm/preset.mjs +9 -9
- package/dist/physics/stopping-distance/preset.mjs +3 -3
- package/dist/physics/temperature-scales/preset.mjs +105 -116
- package/dist/physics/terminal-velocity/preset.mjs +5 -5
- package/dist/physics/thermal/preset.mjs +5 -5
- package/dist/physics/vector-board/preset.mjs +7 -6
- package/dist/physics/vector-scene.mjs +2 -2
- package/dist/physics/vector-types/preset.mjs +37 -3
- package/dist/physics/water-density/preset.mjs +12 -12
- package/dist/physics/waves/doppler.mjs +2 -2
- package/dist/physics/waves/preset.mjs +4 -4
- package/dist/physics/waves/ripple.mjs +6 -6
- package/dist/physics/waves/string.mjs +5 -5
- package/dist/physics/work-energy/preset.mjs +4 -4
- package/dist/physics/work-potential/index.d.mts +1 -0
- package/dist/physics/work-potential/preset.d.mts +20 -0
- package/dist/physics/work-potential/preset.mjs +276 -0
- package/dist/schemas/index.d.mts +6 -6
- package/dist/schemas/index.mjs +3 -3
- package/dist/statistics/center-spread/preset.mjs +3 -3
- package/dist/statistics/core/descriptive.d.mts +2 -2
- package/dist/statistics/core/descriptive.mjs +2 -2
- package/dist/statistics/core/normal.d.mts +3 -3
- package/dist/statistics/core/normal.mjs +3 -3
- package/dist/statistics/core/sequences.d.mts +1 -1
- package/dist/statistics/galton/preset.mjs +2 -2
- package/dist/statistics/histogram/preset.mjs +6 -6
- package/dist/statistics/normal/preset.mjs +2 -2
- package/dist/statistics/sampling/preset.mjs +4 -4
- package/dist/statistics/sequence/preset.mjs +58 -15
- package/dist/statistics/z-table/preset.mjs +17 -4
- package/package.json +11 -3
- package/styles.css +4 -1
|
@@ -0,0 +1,787 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { getPart, listParts } from "./registry.mjs";
|
|
4
|
+
import { partState, solveCircuit } from "./solve.mjs";
|
|
5
|
+
import { addPart, addWire, deletePart, disconnectWire, movePart, retargetWire, rotatePart, setGround, setWireWaypoints, spliceIntoWire, tapWire, terminalOf, updateProps, wirePolyline } from "./editor-ops.mjs";
|
|
6
|
+
import { CircuitScene } from "./CircuitScene.mjs";
|
|
7
|
+
import { EBtn, Field, NumInput, Panel, TextInput } from "./editor-ui.mjs";
|
|
8
|
+
import { useEffect, useRef, useState } from "react";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
|
|
11
|
+
//#region src/build/CircuitEditor.tsx
|
|
12
|
+
/**
|
|
13
|
+
* CircuitEditor — the authoring surface. Pick a part from the palette to drop it on
|
|
14
|
+
* the canvas, drag parts to lay them out, click two pins to wire them, and tune the
|
|
15
|
+
* selected part in the inspector. The doc solves live as you build, so the lamp lights
|
|
16
|
+
* and current flows while you author. Emits the CircuitDoc via `onChange`; the UI is
|
|
17
|
+
* themed from the host's design tokens (see editor-ui).
|
|
18
|
+
*/
|
|
19
|
+
const SNAP = 10;
|
|
20
|
+
const snap = (n) => Math.round(n / SNAP) * SNAP;
|
|
21
|
+
const emptyDoc = {
|
|
22
|
+
parts: [],
|
|
23
|
+
nodes: [],
|
|
24
|
+
size: {
|
|
25
|
+
w: 560,
|
|
26
|
+
h: 300
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/** distance from point p to segment a→b. */
|
|
30
|
+
function segDist(p, a, b) {
|
|
31
|
+
const dx = b[0] - a[0], dy = b[1] - a[1];
|
|
32
|
+
const len2 = dx * dx + dy * dy;
|
|
33
|
+
const t = len2 ? Math.max(0, Math.min(1, ((p.x - a[0]) * dx + (p.y - a[1]) * dy) / len2)) : 0;
|
|
34
|
+
return Math.hypot(p.x - (a[0] + t * dx), p.y - (a[1] + t * dy));
|
|
35
|
+
}
|
|
36
|
+
/** the part pin whose terminal is within `thresh` px of point `at` (nearest wins, or null). */
|
|
37
|
+
function pinAt(doc, at, thresh = 16) {
|
|
38
|
+
let best = null, bd = thresh;
|
|
39
|
+
for (const p of doc.parts) {
|
|
40
|
+
const def = getPart(p.kind);
|
|
41
|
+
if (!def) continue;
|
|
42
|
+
for (const pin of def.pins) {
|
|
43
|
+
const t = def.terminalAt(p, pin);
|
|
44
|
+
const d = Math.hypot(at.x - t.x, at.y - t.y);
|
|
45
|
+
if (d < bd) {
|
|
46
|
+
bd = d;
|
|
47
|
+
best = {
|
|
48
|
+
partId: p.id,
|
|
49
|
+
pin
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return best;
|
|
55
|
+
}
|
|
56
|
+
/** The full routed polyline of a wire (through its bend points), as tuples. */
|
|
57
|
+
function wirePts(doc, w) {
|
|
58
|
+
const ta = terminalOf(doc, w.a), tb = terminalOf(doc, w.b);
|
|
59
|
+
if (!ta || !tb) return [];
|
|
60
|
+
return wirePolyline(ta, w.mid ?? [], tb).map((p) => [p.x, p.y]);
|
|
61
|
+
}
|
|
62
|
+
/** the wire whose routed path passes within `thresh` px of point `at` (or null). */
|
|
63
|
+
function wireAt(doc, at, thresh = 16) {
|
|
64
|
+
let best = null, bestD = thresh;
|
|
65
|
+
for (const w of doc.wires ?? []) {
|
|
66
|
+
const route = wirePts(doc, w);
|
|
67
|
+
for (let i = 0; i < route.length - 1; i++) {
|
|
68
|
+
const d = segDist(at, route[i], route[i + 1]);
|
|
69
|
+
if (d < bestD) {
|
|
70
|
+
bestD = d;
|
|
71
|
+
best = w.id;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return best;
|
|
76
|
+
}
|
|
77
|
+
/** A tiny preview of a part's own glyph for the palette (label cropped out of view). */
|
|
78
|
+
function PartThumb({ kind }) {
|
|
79
|
+
const def = getPart(kind);
|
|
80
|
+
if (!def) return null;
|
|
81
|
+
const inst = {
|
|
82
|
+
id: "_t",
|
|
83
|
+
kind,
|
|
84
|
+
at: {
|
|
85
|
+
x: 40,
|
|
86
|
+
y: 34
|
|
87
|
+
},
|
|
88
|
+
orient: "h",
|
|
89
|
+
props: def.defaultProps,
|
|
90
|
+
pins: {}
|
|
91
|
+
};
|
|
92
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
93
|
+
viewBox: "6 18 68 30",
|
|
94
|
+
width: 46,
|
|
95
|
+
height: 20,
|
|
96
|
+
"aria-hidden": true,
|
|
97
|
+
style: { flexShrink: 0 },
|
|
98
|
+
children: def.render(inst, {
|
|
99
|
+
live: false,
|
|
100
|
+
i: 0,
|
|
101
|
+
v: 0,
|
|
102
|
+
power: 0,
|
|
103
|
+
pinV: () => 0
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function CircuitEditor({ value, onChange }) {
|
|
108
|
+
const doc = value ?? emptyDoc;
|
|
109
|
+
const W = doc.size?.w ?? 560;
|
|
110
|
+
const [selected, setSelected] = useState(null);
|
|
111
|
+
const [selectedWire, setSelectedWire] = useState(null);
|
|
112
|
+
const [pending, setPending] = useState(null);
|
|
113
|
+
const [preview, setPreview] = useState(null);
|
|
114
|
+
const [endDrag, setEndDrag] = useState(null);
|
|
115
|
+
const [full, setFull] = useState(false);
|
|
116
|
+
const hostRef = useRef(null);
|
|
117
|
+
const docRef = useRef(doc);
|
|
118
|
+
docRef.current = doc;
|
|
119
|
+
const onChangeRef = useRef(onChange);
|
|
120
|
+
onChangeRef.current = onChange;
|
|
121
|
+
const pendingRef = useRef(pending);
|
|
122
|
+
pendingRef.current = pending;
|
|
123
|
+
const previewRef = useRef(preview);
|
|
124
|
+
previewRef.current = preview;
|
|
125
|
+
const sel = doc.parts.find((p) => p.id === selected) ?? null;
|
|
126
|
+
const selDef = sel ? getPart(sel.kind) : null;
|
|
127
|
+
const sol = solveCircuit(doc);
|
|
128
|
+
const shorted = sol.shorted.map((id) => doc.parts.find((p) => p.id === id)).filter((p) => !!p);
|
|
129
|
+
const damaged = doc.parts.map((p) => ({
|
|
130
|
+
p,
|
|
131
|
+
st: partState(p, sol)
|
|
132
|
+
})).filter((x) => !!x.st.damage);
|
|
133
|
+
const place = (kind) => {
|
|
134
|
+
const d = docRef.current;
|
|
135
|
+
const n = d.parts.length;
|
|
136
|
+
const next = addPart(d, kind, {
|
|
137
|
+
x: snap(120 + n % 3 * 150),
|
|
138
|
+
y: snap(80 + Math.floor(n / 3) * 90)
|
|
139
|
+
});
|
|
140
|
+
onChangeRef.current(next);
|
|
141
|
+
setSelected(next.parts[next.parts.length - 1]?.id ?? null);
|
|
142
|
+
};
|
|
143
|
+
const dropAt = (kind, clientX, clientY) => {
|
|
144
|
+
const host = hostRef.current;
|
|
145
|
+
if (!host) {
|
|
146
|
+
place(kind);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const r = host.getBoundingClientRect();
|
|
150
|
+
if (clientX < r.left || clientX > r.right || clientY < r.top || clientY > r.bottom) {
|
|
151
|
+
place(kind);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const sc = r.width / W;
|
|
155
|
+
const at = {
|
|
156
|
+
x: snap((clientX - r.left) / sc),
|
|
157
|
+
y: snap((clientY - r.top) / sc)
|
|
158
|
+
};
|
|
159
|
+
const d = docRef.current;
|
|
160
|
+
const wid = wireAt(d, at);
|
|
161
|
+
if (wid && kind === "node") {
|
|
162
|
+
const { doc: next, pin } = tapWire(d, wid, at);
|
|
163
|
+
onChangeRef.current(next);
|
|
164
|
+
setSelected(pin.partId);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const next = wid ? spliceIntoWire(d, wid, kind, at) : addPart(d, kind, at);
|
|
168
|
+
onChangeRef.current(next);
|
|
169
|
+
setSelected(next.parts[next.parts.length - 1]?.id ?? null);
|
|
170
|
+
};
|
|
171
|
+
const startPaletteDrag = (kind) => {
|
|
172
|
+
const up = (ev) => {
|
|
173
|
+
window.removeEventListener("pointerup", up);
|
|
174
|
+
dropAt(kind, ev.clientX, ev.clientY);
|
|
175
|
+
};
|
|
176
|
+
window.addEventListener("pointerup", up);
|
|
177
|
+
};
|
|
178
|
+
const toCanvas = (cx, cy) => {
|
|
179
|
+
const host = hostRef.current;
|
|
180
|
+
if (!host) return {
|
|
181
|
+
x: 0,
|
|
182
|
+
y: 0
|
|
183
|
+
};
|
|
184
|
+
const r = host.getBoundingClientRect();
|
|
185
|
+
const scale = r.width / W;
|
|
186
|
+
return {
|
|
187
|
+
x: (cx - r.left) / scale,
|
|
188
|
+
y: (cy - r.top) / scale
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
if (!pending) {
|
|
193
|
+
setPreview(null);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const move = (ev) => {
|
|
197
|
+
const at = toCanvas(ev.clientX, ev.clientY);
|
|
198
|
+
const d = docRef.current;
|
|
199
|
+
setPreview({
|
|
200
|
+
to: at,
|
|
201
|
+
valid: !!pinAt(d, at) || !!wireAt(d, at)
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
const key = (ev) => {
|
|
205
|
+
if (ev.key === "Escape") setPending(null);
|
|
206
|
+
};
|
|
207
|
+
window.addEventListener("pointermove", move);
|
|
208
|
+
window.addEventListener("keydown", key);
|
|
209
|
+
return () => {
|
|
210
|
+
window.removeEventListener("pointermove", move);
|
|
211
|
+
window.removeEventListener("keydown", key);
|
|
212
|
+
};
|
|
213
|
+
}, [pending]);
|
|
214
|
+
/** Create the wire the user drew (a→b) carrying its routing bends. Uses addWire (not connect)
|
|
215
|
+
* so it is created even between pins already on the same net — a drawn wire never vanishes. */
|
|
216
|
+
const connectWithMids = (d, a, b, mids) => addWire(d, a, b, mids);
|
|
217
|
+
const handlePinClick = (from) => {
|
|
218
|
+
const p = pendingRef.current;
|
|
219
|
+
if (!p) {
|
|
220
|
+
setPending({
|
|
221
|
+
from,
|
|
222
|
+
mids: []
|
|
223
|
+
});
|
|
224
|
+
setSelected(from.partId);
|
|
225
|
+
setSelectedWire(null);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (p.from.partId === from.partId && p.from.pin === from.pin) {
|
|
229
|
+
setPending(null);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
onChangeRef.current(connectWithMids(docRef.current, p.from, from, p.mids));
|
|
233
|
+
setPending(null);
|
|
234
|
+
setSelected(from.partId);
|
|
235
|
+
};
|
|
236
|
+
const beginMove = (partId, e, onClick) => {
|
|
237
|
+
const part = docRef.current.parts.find((p) => p.id === partId);
|
|
238
|
+
const host = hostRef.current;
|
|
239
|
+
if (!part || !host) return;
|
|
240
|
+
e.preventDefault();
|
|
241
|
+
const scale = host.getBoundingClientRect().width / W;
|
|
242
|
+
const sx = e.clientX, sy = e.clientY, ox = part.at.x, oy = part.at.y;
|
|
243
|
+
let moved = false;
|
|
244
|
+
const move = (ev) => {
|
|
245
|
+
if (!moved && Math.abs(ev.clientX - sx) + Math.abs(ev.clientY - sy) > 4) moved = true;
|
|
246
|
+
if (moved) onChangeRef.current(movePart(docRef.current, partId, {
|
|
247
|
+
x: snap(ox + (ev.clientX - sx) / scale),
|
|
248
|
+
y: snap(oy + (ev.clientY - sy) / scale)
|
|
249
|
+
}));
|
|
250
|
+
};
|
|
251
|
+
const up = () => {
|
|
252
|
+
window.removeEventListener("pointermove", move);
|
|
253
|
+
window.removeEventListener("pointerup", up);
|
|
254
|
+
if (!moved) onClick();
|
|
255
|
+
};
|
|
256
|
+
window.addEventListener("pointermove", move);
|
|
257
|
+
window.addEventListener("pointerup", up);
|
|
258
|
+
};
|
|
259
|
+
const onPartPointerDown = (partId, e) => beginMove(partId, e, () => {
|
|
260
|
+
setSelected(partId);
|
|
261
|
+
setSelectedWire(null);
|
|
262
|
+
setPending(null);
|
|
263
|
+
});
|
|
264
|
+
const onPinPointerDown = (partId, pin, e) => {
|
|
265
|
+
if (docRef.current.parts.find((p) => p.id === partId)?.kind === "node") {
|
|
266
|
+
beginMove(partId, e, () => handlePinClick({
|
|
267
|
+
partId,
|
|
268
|
+
pin
|
|
269
|
+
}));
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
e.preventDefault();
|
|
273
|
+
const sx = e.clientX, sy = e.clientY;
|
|
274
|
+
let moved = false;
|
|
275
|
+
const move = (ev) => {
|
|
276
|
+
if (Math.abs(ev.clientX - sx) + Math.abs(ev.clientY - sy) > 4) moved = true;
|
|
277
|
+
};
|
|
278
|
+
const up = () => {
|
|
279
|
+
window.removeEventListener("pointermove", move);
|
|
280
|
+
window.removeEventListener("pointerup", up);
|
|
281
|
+
if (!moved) handlePinClick({
|
|
282
|
+
partId,
|
|
283
|
+
pin
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
window.addEventListener("pointermove", move);
|
|
287
|
+
window.addEventListener("pointerup", up);
|
|
288
|
+
};
|
|
289
|
+
const onWireClick = (wireId) => {
|
|
290
|
+
const p = pendingRef.current;
|
|
291
|
+
if (p) {
|
|
292
|
+
const at = previewRef.current?.to ?? terminalOf(docRef.current, p.from) ?? {
|
|
293
|
+
x: 0,
|
|
294
|
+
y: 0
|
|
295
|
+
};
|
|
296
|
+
const { doc: d2, pin: jp } = tapWire(docRef.current, wireId, at);
|
|
297
|
+
onChangeRef.current(connectWithMids(d2, p.from, jp, p.mids));
|
|
298
|
+
setPending(null);
|
|
299
|
+
setSelected(jp.partId);
|
|
300
|
+
} else {
|
|
301
|
+
setSelectedWire(wireId);
|
|
302
|
+
setSelected(null);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
const onBackground = (e) => {
|
|
306
|
+
const p = pendingRef.current;
|
|
307
|
+
if (p) {
|
|
308
|
+
const at = toCanvas(e.clientX, e.clientY);
|
|
309
|
+
setPending({
|
|
310
|
+
from: p.from,
|
|
311
|
+
mids: [...p.mids, {
|
|
312
|
+
x: snap(at.x),
|
|
313
|
+
y: snap(at.y)
|
|
314
|
+
}]
|
|
315
|
+
});
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
setSelected(null);
|
|
319
|
+
setSelectedWire(null);
|
|
320
|
+
};
|
|
321
|
+
const snapPt = (p) => ({
|
|
322
|
+
x: snap(p.x),
|
|
323
|
+
y: snap(p.y)
|
|
324
|
+
});
|
|
325
|
+
const pruneCollinear = (ta, mids, tb) => {
|
|
326
|
+
const anchors = [
|
|
327
|
+
ta,
|
|
328
|
+
...mids,
|
|
329
|
+
tb
|
|
330
|
+
];
|
|
331
|
+
return mids.filter((m, i) => segDist(m, [anchors[i].x, anchors[i].y], [anchors[i + 2].x, anchors[i + 2].y]) > 3);
|
|
332
|
+
};
|
|
333
|
+
const dragBend = (wireId, startMids, index, e) => {
|
|
334
|
+
e.preventDefault();
|
|
335
|
+
const d0 = docRef.current;
|
|
336
|
+
const w0 = (d0.wires ?? []).find((x) => x.id === wireId);
|
|
337
|
+
const ta = w0 && terminalOf(d0, w0.a), tb = w0 && terminalOf(d0, w0.b);
|
|
338
|
+
if (!ta || !tb) return;
|
|
339
|
+
let mids = startMids;
|
|
340
|
+
let moved = false;
|
|
341
|
+
const move = (ev) => {
|
|
342
|
+
moved = true;
|
|
343
|
+
const at = snapPt(toCanvas(ev.clientX, ev.clientY));
|
|
344
|
+
mids = mids.map((m, i) => i === index ? at : m);
|
|
345
|
+
onChangeRef.current(setWireWaypoints(docRef.current, wireId, mids));
|
|
346
|
+
};
|
|
347
|
+
const up = () => {
|
|
348
|
+
window.removeEventListener("pointermove", move);
|
|
349
|
+
window.removeEventListener("pointerup", up);
|
|
350
|
+
if (moved) onChangeRef.current(setWireWaypoints(docRef.current, wireId, pruneCollinear(ta, mids, tb)));
|
|
351
|
+
};
|
|
352
|
+
window.addEventListener("pointermove", move);
|
|
353
|
+
window.addEventListener("pointerup", up);
|
|
354
|
+
};
|
|
355
|
+
const onWireWaypointDown = (wireId, index, e) => {
|
|
356
|
+
const w = (docRef.current.wires ?? []).find((x) => x.id === wireId);
|
|
357
|
+
if (w?.mid) dragBend(wireId, [...w.mid], index, e);
|
|
358
|
+
};
|
|
359
|
+
const onWireBodyDown = (wireId, e) => {
|
|
360
|
+
const d = docRef.current;
|
|
361
|
+
const w = (d.wires ?? []).find((x) => x.id === wireId);
|
|
362
|
+
const ta = w && terminalOf(d, w.a), tb = w && terminalOf(d, w.b);
|
|
363
|
+
if (!w || !ta || !tb) return;
|
|
364
|
+
const at = toCanvas(e.clientX, e.clientY);
|
|
365
|
+
const mids = [...w.mid ?? []];
|
|
366
|
+
let idx = mids.findIndex((m) => Math.hypot(at.x - m.x, at.y - m.y) < 10);
|
|
367
|
+
if (idx < 0) {
|
|
368
|
+
const anchors = [
|
|
369
|
+
ta,
|
|
370
|
+
...mids,
|
|
371
|
+
tb
|
|
372
|
+
];
|
|
373
|
+
let seg = 0, sd = Infinity;
|
|
374
|
+
for (let i = 0; i < anchors.length - 1; i++) {
|
|
375
|
+
const dd = segDist(at, [anchors[i].x, anchors[i].y], [anchors[i + 1].x, anchors[i + 1].y]);
|
|
376
|
+
if (dd < sd) {
|
|
377
|
+
sd = dd;
|
|
378
|
+
seg = i;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
mids.splice(seg, 0, snapPt(at));
|
|
382
|
+
idx = seg;
|
|
383
|
+
}
|
|
384
|
+
dragBend(wireId, mids, idx, e);
|
|
385
|
+
};
|
|
386
|
+
const onWireEndDown = (wireId, end, e) => {
|
|
387
|
+
const d0 = docRef.current;
|
|
388
|
+
const w = (d0.wires ?? []).find((x) => x.id === wireId);
|
|
389
|
+
if (!w) return;
|
|
390
|
+
e.preventDefault();
|
|
391
|
+
const fixedPos = terminalOf(d0, end === "a" ? w.b : w.a) ?? {
|
|
392
|
+
x: 0,
|
|
393
|
+
y: 0
|
|
394
|
+
};
|
|
395
|
+
setEndDrag({
|
|
396
|
+
fixedPos,
|
|
397
|
+
to: fixedPos,
|
|
398
|
+
valid: false
|
|
399
|
+
});
|
|
400
|
+
let moved = false, last = fixedPos;
|
|
401
|
+
const move = (ev) => {
|
|
402
|
+
moved = true;
|
|
403
|
+
const at = toCanvas(ev.clientX, ev.clientY);
|
|
404
|
+
last = at;
|
|
405
|
+
setEndDrag({
|
|
406
|
+
fixedPos,
|
|
407
|
+
to: at,
|
|
408
|
+
valid: !!pinAt(docRef.current, at) || !!wireAt(docRef.current, at)
|
|
409
|
+
});
|
|
410
|
+
};
|
|
411
|
+
const up = () => {
|
|
412
|
+
window.removeEventListener("pointermove", move);
|
|
413
|
+
window.removeEventListener("pointerup", up);
|
|
414
|
+
setEndDrag(null);
|
|
415
|
+
if (!moved) return;
|
|
416
|
+
const pin = pinAt(docRef.current, last);
|
|
417
|
+
if (pin) {
|
|
418
|
+
onChangeRef.current(retargetWire(docRef.current, wireId, end, pin));
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const wid = wireAt(docRef.current, last);
|
|
422
|
+
if (wid && wid !== wireId) {
|
|
423
|
+
const { doc: d2, pin: jp } = tapWire(docRef.current, wid, last);
|
|
424
|
+
onChangeRef.current(retargetWire(d2, wireId, end, jp));
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
window.addEventListener("pointermove", move);
|
|
429
|
+
window.addEventListener("pointerup", up);
|
|
430
|
+
};
|
|
431
|
+
const set = (patch) => {
|
|
432
|
+
if (sel) onChange(updateProps(doc, sel.id, patch));
|
|
433
|
+
};
|
|
434
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
435
|
+
style: full ? {
|
|
436
|
+
position: "fixed",
|
|
437
|
+
inset: 0,
|
|
438
|
+
zIndex: 60,
|
|
439
|
+
background: "var(--background, #fff)",
|
|
440
|
+
padding: 18,
|
|
441
|
+
overflow: "auto",
|
|
442
|
+
display: "grid",
|
|
443
|
+
gridTemplateColumns: "180px 1fr 264px",
|
|
444
|
+
gap: 16,
|
|
445
|
+
alignItems: "start"
|
|
446
|
+
} : {
|
|
447
|
+
display: "grid",
|
|
448
|
+
gridTemplateColumns: "172px 1fr 244px",
|
|
449
|
+
gap: 14,
|
|
450
|
+
alignItems: "start"
|
|
451
|
+
},
|
|
452
|
+
children: [
|
|
453
|
+
/* @__PURE__ */ jsx(Panel, {
|
|
454
|
+
title: "Parts",
|
|
455
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
456
|
+
style: {
|
|
457
|
+
display: "flex",
|
|
458
|
+
flexDirection: "column",
|
|
459
|
+
gap: 4
|
|
460
|
+
},
|
|
461
|
+
children: listParts().map((d) => /* @__PURE__ */ jsxs("button", {
|
|
462
|
+
type: "button",
|
|
463
|
+
onPointerDown: () => startPaletteDrag(d.kind),
|
|
464
|
+
title: `add ${d.label} — or drag onto a wire to splice it in`,
|
|
465
|
+
style: {
|
|
466
|
+
display: "flex",
|
|
467
|
+
alignItems: "center",
|
|
468
|
+
gap: 10,
|
|
469
|
+
width: "100%",
|
|
470
|
+
textAlign: "left",
|
|
471
|
+
padding: "7px 9px",
|
|
472
|
+
fontSize: 13,
|
|
473
|
+
fontWeight: 600,
|
|
474
|
+
color: "var(--foreground, #1c1c1c)",
|
|
475
|
+
background: "transparent",
|
|
476
|
+
border: "1px solid transparent",
|
|
477
|
+
borderRadius: "calc(var(--radius, 0.6rem) - 2px)",
|
|
478
|
+
cursor: "pointer"
|
|
479
|
+
},
|
|
480
|
+
onMouseEnter: (e) => {
|
|
481
|
+
e.currentTarget.style.background = "var(--accent, #f1f1f3)";
|
|
482
|
+
e.currentTarget.style.borderColor = "var(--border, #e4e4e7)";
|
|
483
|
+
},
|
|
484
|
+
onMouseLeave: (e) => {
|
|
485
|
+
e.currentTarget.style.background = "transparent";
|
|
486
|
+
e.currentTarget.style.borderColor = "transparent";
|
|
487
|
+
},
|
|
488
|
+
children: [
|
|
489
|
+
/* @__PURE__ */ jsx(PartThumb, { kind: d.kind }),
|
|
490
|
+
/* @__PURE__ */ jsx("span", {
|
|
491
|
+
style: { flex: 1 },
|
|
492
|
+
children: d.label
|
|
493
|
+
}),
|
|
494
|
+
/* @__PURE__ */ jsx("span", {
|
|
495
|
+
style: {
|
|
496
|
+
color: "var(--muted-foreground, #999)",
|
|
497
|
+
fontSize: 15,
|
|
498
|
+
lineHeight: 1
|
|
499
|
+
},
|
|
500
|
+
children: "+"
|
|
501
|
+
})
|
|
502
|
+
]
|
|
503
|
+
}, d.kind))
|
|
504
|
+
})
|
|
505
|
+
}),
|
|
506
|
+
/* @__PURE__ */ jsxs("div", {
|
|
507
|
+
style: {
|
|
508
|
+
display: "flex",
|
|
509
|
+
flexDirection: "column",
|
|
510
|
+
gap: 8
|
|
511
|
+
},
|
|
512
|
+
children: [
|
|
513
|
+
/* @__PURE__ */ jsxs("div", {
|
|
514
|
+
style: {
|
|
515
|
+
display: "flex",
|
|
516
|
+
alignItems: "center",
|
|
517
|
+
gap: 10,
|
|
518
|
+
fontSize: 12,
|
|
519
|
+
color: "var(--muted-foreground, #777)"
|
|
520
|
+
},
|
|
521
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
522
|
+
style: { flex: 1 },
|
|
523
|
+
children: pending ? "Click another pin to finish the wire (or a wire to branch off it). Click empty space to drop a bend and keep routing. Press Esc to cancel." : "Click a pin dot to start a wire, then click another pin to finish (no need to hold). Drag a part or junction to move it. Click a wire to select it (delete it in the inspector)."
|
|
524
|
+
}), /* @__PURE__ */ jsx(EBtn, {
|
|
525
|
+
variant: "ghost",
|
|
526
|
+
onClick: () => setFull((f) => !f),
|
|
527
|
+
children: full ? "⤡ exit fullscreen" : "⤢ fullscreen"
|
|
528
|
+
})]
|
|
529
|
+
}),
|
|
530
|
+
shorted.length > 0 && /* @__PURE__ */ jsxs("div", {
|
|
531
|
+
role: "alert",
|
|
532
|
+
style: {
|
|
533
|
+
fontSize: 12.5,
|
|
534
|
+
lineHeight: 1.4,
|
|
535
|
+
padding: "8px 11px",
|
|
536
|
+
borderRadius: "var(--radius, 8px)",
|
|
537
|
+
color: "var(--destructive-foreground, #fff)",
|
|
538
|
+
background: "var(--destructive, oklch(0.58 0.22 27))"
|
|
539
|
+
},
|
|
540
|
+
children: [
|
|
541
|
+
"⚠ Short circuit: ",
|
|
542
|
+
shorted.map((p) => getPart(p.kind)?.label ?? p.kind).join(", "),
|
|
543
|
+
" ",
|
|
544
|
+
shorted.length > 1 ? "have" : "has",
|
|
545
|
+
" both terminals on the same net. To clear it: select the part and un-ground a terminal (the ⏚ grounded button), or click the shorting wire to delete it. A source needs a component (bulb, resistor) in the loop between + and −."
|
|
546
|
+
]
|
|
547
|
+
}),
|
|
548
|
+
damaged.length > 0 && /* @__PURE__ */ jsxs("div", {
|
|
549
|
+
role: "alert",
|
|
550
|
+
style: {
|
|
551
|
+
fontSize: 12.5,
|
|
552
|
+
lineHeight: 1.4,
|
|
553
|
+
padding: "8px 11px",
|
|
554
|
+
borderRadius: "var(--radius, 8px)",
|
|
555
|
+
color: "var(--destructive-foreground, #fff)",
|
|
556
|
+
background: "var(--destructive, oklch(0.58 0.22 27))"
|
|
557
|
+
},
|
|
558
|
+
children: [
|
|
559
|
+
"🔥 Overload: ",
|
|
560
|
+
damaged.map((d) => `${getPart(d.p.kind)?.label ?? d.p.kind} (${d.st.damage === "overvoltage" ? `${Math.abs(d.st.v).toFixed(1)} V across` : `${d.st.power.toFixed(2)} W`})`).join(", "),
|
|
561
|
+
" ",
|
|
562
|
+
damaged.length > 1 ? "exceed their ratings" : "exceeds its rating",
|
|
563
|
+
" and would burn out. Lower the supply voltage, raise the resistance, or increase the part's rating in the inspector."
|
|
564
|
+
]
|
|
565
|
+
}),
|
|
566
|
+
/* @__PURE__ */ jsx("div", {
|
|
567
|
+
ref: hostRef,
|
|
568
|
+
style: { touchAction: "none" },
|
|
569
|
+
children: /* @__PURE__ */ jsx(CircuitScene, {
|
|
570
|
+
doc,
|
|
571
|
+
ariaLabel: "circuit editor canvas",
|
|
572
|
+
selectedId: selected ?? void 0,
|
|
573
|
+
editor: {
|
|
574
|
+
showPins: true,
|
|
575
|
+
onPinPointerDown,
|
|
576
|
+
onSelect: (id) => {
|
|
577
|
+
setSelected(id);
|
|
578
|
+
setSelectedWire(null);
|
|
579
|
+
},
|
|
580
|
+
onPartPointerDown,
|
|
581
|
+
onBackground,
|
|
582
|
+
onWireClick,
|
|
583
|
+
selectedWireId: selectedWire ?? void 0,
|
|
584
|
+
onWireBodyDown,
|
|
585
|
+
onWireWaypointDown,
|
|
586
|
+
onWireEndDown,
|
|
587
|
+
wirePreview: endDrag ? {
|
|
588
|
+
from: endDrag.fixedPos,
|
|
589
|
+
to: endDrag.to,
|
|
590
|
+
valid: endDrag.valid
|
|
591
|
+
} : pending && preview ? {
|
|
592
|
+
from: terminalOf(doc, pending.from) ?? preview.to,
|
|
593
|
+
mids: pending.mids,
|
|
594
|
+
to: preview.to,
|
|
595
|
+
valid: preview.valid
|
|
596
|
+
} : void 0
|
|
597
|
+
}
|
|
598
|
+
})
|
|
599
|
+
})
|
|
600
|
+
]
|
|
601
|
+
}),
|
|
602
|
+
/* @__PURE__ */ jsx(Panel, {
|
|
603
|
+
title: "Inspector",
|
|
604
|
+
children: selectedWire ? /* @__PURE__ */ jsxs("div", {
|
|
605
|
+
style: {
|
|
606
|
+
display: "flex",
|
|
607
|
+
flexDirection: "column",
|
|
608
|
+
gap: 12
|
|
609
|
+
},
|
|
610
|
+
children: [
|
|
611
|
+
/* @__PURE__ */ jsx("span", {
|
|
612
|
+
style: {
|
|
613
|
+
fontSize: 14,
|
|
614
|
+
fontWeight: 700,
|
|
615
|
+
color: "var(--foreground, #1c1c1c)"
|
|
616
|
+
},
|
|
617
|
+
children: "Wire"
|
|
618
|
+
}),
|
|
619
|
+
/* @__PURE__ */ jsx("div", {
|
|
620
|
+
style: {
|
|
621
|
+
fontSize: 13,
|
|
622
|
+
color: "var(--muted-foreground, #777)",
|
|
623
|
+
lineHeight: 1.5
|
|
624
|
+
},
|
|
625
|
+
children: "Drag the wire (or a square bend handle) to position its path. Drag an end ring off its pin to detach / re-attach it. Drag a bend onto the straight line to remove it."
|
|
626
|
+
}),
|
|
627
|
+
/* @__PURE__ */ jsx(EBtn, {
|
|
628
|
+
variant: "danger",
|
|
629
|
+
title: "delete wire",
|
|
630
|
+
onClick: () => {
|
|
631
|
+
onChange(disconnectWire(doc, selectedWire));
|
|
632
|
+
setSelectedWire(null);
|
|
633
|
+
},
|
|
634
|
+
children: "🗑 delete wire"
|
|
635
|
+
})
|
|
636
|
+
]
|
|
637
|
+
}) : !sel || !selDef ? /* @__PURE__ */ jsx("div", {
|
|
638
|
+
style: {
|
|
639
|
+
fontSize: 13,
|
|
640
|
+
color: "var(--muted-foreground, #777)",
|
|
641
|
+
lineHeight: 1.5
|
|
642
|
+
},
|
|
643
|
+
children: "Select a part or wire on the canvas to edit it, or add a part from the palette."
|
|
644
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
645
|
+
style: {
|
|
646
|
+
display: "flex",
|
|
647
|
+
flexDirection: "column",
|
|
648
|
+
gap: 14
|
|
649
|
+
},
|
|
650
|
+
children: [
|
|
651
|
+
/* @__PURE__ */ jsxs("div", {
|
|
652
|
+
style: {
|
|
653
|
+
display: "flex",
|
|
654
|
+
alignItems: "center",
|
|
655
|
+
gap: 10
|
|
656
|
+
},
|
|
657
|
+
children: [/* @__PURE__ */ jsx(PartThumb, { kind: sel.kind }), /* @__PURE__ */ jsx("span", {
|
|
658
|
+
style: {
|
|
659
|
+
fontSize: 14,
|
|
660
|
+
fontWeight: 700,
|
|
661
|
+
color: "var(--foreground, #1c1c1c)"
|
|
662
|
+
},
|
|
663
|
+
children: selDef.label
|
|
664
|
+
})]
|
|
665
|
+
}),
|
|
666
|
+
(selDef.controls?.length || Object.keys(selDef.defaultProps ?? {}).length > 0) && /* @__PURE__ */ jsxs("div", {
|
|
667
|
+
style: {
|
|
668
|
+
display: "flex",
|
|
669
|
+
flexDirection: "column",
|
|
670
|
+
gap: 9
|
|
671
|
+
},
|
|
672
|
+
children: [selDef.controls?.map((c) => {
|
|
673
|
+
const cur = Number(sel.props?.[c.key] ?? selDef.defaultProps?.[c.key] ?? 0);
|
|
674
|
+
const clamp = (v) => Math.min(c.max ?? Infinity, Math.max(c.min ?? -Infinity, v));
|
|
675
|
+
return /* @__PURE__ */ jsx(Field, {
|
|
676
|
+
label: c.unit ? `${c.label} (${c.unit})` : c.label,
|
|
677
|
+
children: /* @__PURE__ */ jsx(NumInput, {
|
|
678
|
+
value: cur,
|
|
679
|
+
onChange: (v) => set({ [c.key]: clamp(v) }),
|
|
680
|
+
step: c.step ?? 1,
|
|
681
|
+
min: c.min,
|
|
682
|
+
ariaLabel: c.label
|
|
683
|
+
})
|
|
684
|
+
}, c.key);
|
|
685
|
+
}), Object.entries(selDef.defaultProps ?? {}).filter(([key]) => !selDef.controls?.some((c) => c.key === key)).map(([key, dflt]) => {
|
|
686
|
+
const cur = sel.props?.[key] ?? dflt;
|
|
687
|
+
if (typeof dflt === "boolean") return /* @__PURE__ */ jsx(Field, {
|
|
688
|
+
label: key,
|
|
689
|
+
children: /* @__PURE__ */ jsx("input", {
|
|
690
|
+
type: "checkbox",
|
|
691
|
+
checked: !!cur,
|
|
692
|
+
onChange: (e) => set({ [key]: e.target.checked }),
|
|
693
|
+
"aria-label": key
|
|
694
|
+
})
|
|
695
|
+
}, key);
|
|
696
|
+
if (typeof dflt === "string") return /* @__PURE__ */ jsx(Field, {
|
|
697
|
+
label: key,
|
|
698
|
+
children: /* @__PURE__ */ jsx(TextInput, {
|
|
699
|
+
value: String(cur),
|
|
700
|
+
onChange: (v) => set({ [key]: v }),
|
|
701
|
+
ariaLabel: key
|
|
702
|
+
})
|
|
703
|
+
}, key);
|
|
704
|
+
return /* @__PURE__ */ jsx(Field, {
|
|
705
|
+
label: key,
|
|
706
|
+
children: /* @__PURE__ */ jsx(NumInput, {
|
|
707
|
+
value: Number(cur),
|
|
708
|
+
onChange: (v) => set({ [key]: v }),
|
|
709
|
+
step: key === "k" || key === "farads" ? .1 : 1,
|
|
710
|
+
ariaLabel: key
|
|
711
|
+
})
|
|
712
|
+
}, key);
|
|
713
|
+
})]
|
|
714
|
+
}),
|
|
715
|
+
/* @__PURE__ */ jsx("div", { style: {
|
|
716
|
+
height: 1,
|
|
717
|
+
background: "var(--border, #e4e4e7)"
|
|
718
|
+
} }),
|
|
719
|
+
/* @__PURE__ */ jsxs("div", {
|
|
720
|
+
style: {
|
|
721
|
+
display: "flex",
|
|
722
|
+
flexDirection: "column",
|
|
723
|
+
gap: 8
|
|
724
|
+
},
|
|
725
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
726
|
+
style: {
|
|
727
|
+
fontSize: 10.5,
|
|
728
|
+
fontWeight: 700,
|
|
729
|
+
letterSpacing: "0.04em",
|
|
730
|
+
textTransform: "uppercase",
|
|
731
|
+
color: "var(--muted-foreground, #999)"
|
|
732
|
+
},
|
|
733
|
+
children: "Ground"
|
|
734
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
735
|
+
style: {
|
|
736
|
+
display: "flex",
|
|
737
|
+
gap: 6,
|
|
738
|
+
flexWrap: "wrap"
|
|
739
|
+
},
|
|
740
|
+
children: selDef.pins.map((pin) => {
|
|
741
|
+
const grounded = sel.props && sel.pins[pin] === "gnd";
|
|
742
|
+
return /* @__PURE__ */ jsxs(EBtn, {
|
|
743
|
+
active: !!grounded,
|
|
744
|
+
title: grounded ? `disconnect ${pin} from ground` : `tie ${pin} to ground`,
|
|
745
|
+
onClick: () => onChange(setGround(doc, {
|
|
746
|
+
partId: sel.id,
|
|
747
|
+
pin
|
|
748
|
+
})),
|
|
749
|
+
children: [
|
|
750
|
+
pin,
|
|
751
|
+
" ",
|
|
752
|
+
grounded ? "⏚" : "→ gnd"
|
|
753
|
+
]
|
|
754
|
+
}, pin);
|
|
755
|
+
})
|
|
756
|
+
})]
|
|
757
|
+
}),
|
|
758
|
+
/* @__PURE__ */ jsxs("div", {
|
|
759
|
+
style: {
|
|
760
|
+
display: "flex",
|
|
761
|
+
gap: 6,
|
|
762
|
+
flexWrap: "wrap"
|
|
763
|
+
},
|
|
764
|
+
children: [/* @__PURE__ */ jsx(EBtn, {
|
|
765
|
+
variant: "ghost",
|
|
766
|
+
title: "rotate 90°",
|
|
767
|
+
onClick: () => onChange(rotatePart(doc, sel.id)),
|
|
768
|
+
children: "⟳ rotate"
|
|
769
|
+
}), /* @__PURE__ */ jsx(EBtn, {
|
|
770
|
+
variant: "danger",
|
|
771
|
+
title: "delete part",
|
|
772
|
+
onClick: () => {
|
|
773
|
+
onChange(deletePart(doc, sel.id));
|
|
774
|
+
setSelected(null);
|
|
775
|
+
},
|
|
776
|
+
children: "🗑 delete"
|
|
777
|
+
})]
|
|
778
|
+
})
|
|
779
|
+
]
|
|
780
|
+
})
|
|
781
|
+
})
|
|
782
|
+
]
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
//#endregion
|
|
787
|
+
export { CircuitEditor };
|