@classytic/stage 0.2.0 → 0.4.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 +1 -1
- package/README.md +5 -1
- package/dist/_virtual/_rolldown/runtime.mjs +18 -0
- package/dist/assets/index.mjs +0 -1
- package/dist/atomic/aufbau.d.mts +144 -0
- package/dist/atomic/aufbau.mjs +384 -0
- package/dist/atomic/elements.d.mts +67 -0
- package/dist/atomic/elements.mjs +785 -0
- package/dist/atomic/emission.d.mts +112 -0
- package/dist/atomic/emission.mjs +179 -0
- package/dist/atomic/index.d.mts +8 -0
- package/dist/atomic/index.mjs +9 -0
- package/dist/atomic/periodic.d.mts +82 -0
- package/dist/atomic/periodic.mjs +231 -0
- package/dist/atomic/properties.d.mts +100 -0
- package/dist/atomic/properties.mjs +574 -0
- package/dist/atomic/shells.d.mts +137 -0
- package/dist/atomic/shells.mjs +170 -0
- package/dist/atomic/trends.d.mts +148 -0
- package/dist/atomic/trends.mjs +225 -0
- package/dist/builder/Palette.mjs +50 -89
- package/dist/builder/SceneBuilder.mjs +15 -73
- package/dist/chem/chromatography.d.mts +66 -0
- package/dist/chem/chromatography.mjs +63 -0
- package/dist/chem/complex.d.mts +114 -0
- package/dist/chem/complex.mjs +234 -0
- package/dist/chem/cycle.d.mts +75 -0
- package/dist/chem/cycle.mjs +145 -0
- package/dist/chem/equation.d.mts +86 -0
- package/dist/chem/equation.mjs +168 -0
- package/dist/chem/formula.d.mts +90 -0
- package/dist/chem/formula.mjs +201 -0
- package/dist/chem/functional-groups.d.mts +31 -0
- package/dist/chem/functional-groups.mjs +187 -0
- package/dist/chem/hazard.d.mts +94 -0
- package/dist/chem/hazard.mjs +329 -0
- package/dist/chem/index.d.mts +34 -33
- package/dist/chem/index.mjs +34 -28
- package/dist/chem/ionic.d.mts +98 -0
- package/dist/chem/ionic.mjs +156 -0
- package/dist/chem/layout.d.mts +46 -0
- package/dist/chem/layout.mjs +342 -0
- package/dist/chem/lewis.d.mts +79 -0
- package/dist/chem/lewis.mjs +163 -0
- package/dist/chem/molecular-orbital.d.mts +114 -0
- package/dist/chem/molecular-orbital.mjs +201 -0
- package/dist/chem/molecule.d.mts +154 -0
- package/dist/chem/molecule.mjs +282 -0
- package/dist/chem/nmr.d.mts +153 -0
- package/dist/chem/nmr.mjs +165 -0
- package/dist/chem/polymer.d.mts +65 -0
- package/dist/chem/polymer.mjs +179 -0
- package/dist/chem/redox.d.mts +138 -0
- package/dist/chem/redox.mjs +328 -0
- package/dist/chem/relations.d.mts +183 -0
- package/dist/chem/relations.mjs +299 -0
- package/dist/chem/skeleton.d.mts +51 -0
- package/dist/chem/skeleton.mjs +186 -0
- package/dist/chem/solution.d.mts +116 -0
- package/dist/chem/solution.mjs +186 -0
- package/dist/chem/species.d.mts +47 -0
- package/dist/chem/species.mjs +128 -0
- package/dist/chem/stereo.d.mts +108 -0
- package/dist/chem/stereo.mjs +286 -0
- package/dist/chem/stoichiometry.d.mts +95 -0
- package/dist/chem/stoichiometry.mjs +145 -0
- package/dist/chem/synthesis.d.mts +113 -0
- package/dist/chem/synthesis.mjs +281 -0
- package/dist/chem/vsepr.d.mts +80 -0
- package/dist/chem/vsepr.mjs +247 -0
- package/dist/circuit/ac.d.mts +163 -0
- package/dist/circuit/ac.mjs +452 -0
- package/dist/circuit/dc.d.mts +92 -0
- package/dist/circuit/dc.mjs +333 -0
- package/dist/circuit/index.d.mts +5 -92
- package/dist/circuit/index.mjs +5 -332
- package/dist/circuit/network.d.mts +99 -0
- package/dist/circuit/network.mjs +440 -0
- package/dist/circuit/topology.d.mts +102 -0
- package/dist/circuit/topology.mjs +143 -0
- package/dist/colour/absorption.d.mts +79 -0
- package/dist/colour/absorption.mjs +137 -0
- package/dist/colour/index.d.mts +6 -0
- package/dist/colour/index.mjs +7 -0
- package/dist/colour/name.d.mts +14 -0
- package/dist/colour/name.mjs +76 -0
- package/dist/colour/observer.d.mts +31 -0
- package/dist/colour/observer.mjs +46 -0
- package/dist/colour/spectrum.d.mts +61 -0
- package/dist/colour/spectrum.mjs +108 -0
- package/dist/colour/srgb.d.mts +49 -0
- package/dist/colour/srgb.mjs +108 -0
- package/dist/core/constants.d.mts +138 -0
- package/dist/core/constants.mjs +139 -0
- package/dist/core/index.d.mts +4 -1
- package/dist/core/index.mjs +4 -1
- package/dist/core/math.d.mts +26 -0
- package/dist/core/math.mjs +37 -0
- package/dist/core/vec3.d.mts +94 -0
- package/dist/core/vec3.mjs +123 -0
- package/dist/core/worked.d.mts +35 -0
- package/dist/core/worked.mjs +44 -0
- package/dist/electro/cell.d.mts +102 -0
- package/dist/electro/cell.mjs +170 -0
- package/dist/electro/conductivity.d.mts +157 -0
- package/dist/electro/conductivity.mjs +156 -0
- package/dist/electro/couples.d.mts +114 -0
- package/dist/electro/couples.mjs +334 -0
- package/dist/electro/electrolysis.d.mts +96 -0
- package/dist/electro/electrolysis.mjs +274 -0
- package/dist/electro/faraday.d.mts +150 -0
- package/dist/electro/faraday.mjs +118 -0
- package/dist/electro/index.d.mts +6 -0
- package/dist/electro/index.mjs +7 -0
- package/dist/finance/accounting/adjustments.d.mts +17 -0
- package/dist/finance/accounting/adjustments.mjs +202 -0
- package/dist/finance/accounting/analysis.d.mts +8 -0
- package/dist/finance/accounting/analysis.mjs +205 -0
- package/dist/finance/accounting/clubs.d.mts +21 -0
- package/dist/finance/accounting/clubs.mjs +217 -0
- package/dist/finance/accounting/company-statements.d.mts +7 -0
- package/dist/finance/accounting/company-statements.mjs +150 -0
- package/dist/finance/accounting/harness.d.mts +7 -0
- package/dist/finance/accounting/harness.mjs +45 -0
- package/dist/finance/accounting/index.d.mts +18 -0
- package/dist/finance/accounting/index.mjs +18 -0
- package/dist/finance/accounting/journalize.d.mts +16 -0
- package/dist/finance/accounting/journalize.mjs +128 -0
- package/dist/finance/accounting/manufacturing.d.mts +8 -0
- package/dist/finance/accounting/manufacturing.mjs +236 -0
- package/dist/finance/accounting/partnership.d.mts +7 -0
- package/dist/finance/accounting/partnership.mjs +152 -0
- package/dist/finance/accounting/period-case.d.mts +6 -0
- package/dist/finance/accounting/period-case.mjs +71 -0
- package/dist/finance/accounting/post.d.mts +9 -0
- package/dist/finance/accounting/post.mjs +84 -0
- package/dist/finance/accounting/precision.d.mts +9 -0
- package/dist/finance/accounting/precision.mjs +15 -0
- package/dist/finance/accounting/rules.d.mts +21 -0
- package/dist/finance/accounting/rules.mjs +37 -0
- package/dist/finance/accounting/solve.d.mts +28 -0
- package/dist/finance/accounting/solve.mjs +92 -0
- package/dist/finance/accounting/statements.d.mts +7 -0
- package/dist/finance/accounting/statements.mjs +142 -0
- package/dist/finance/accounting/types.d.mts +649 -0
- package/dist/finance/accounting/validate.d.mts +7 -0
- package/dist/finance/accounting/validate.mjs +67 -0
- package/dist/finance/accounting/verification.d.mts +24 -0
- package/dist/finance/accounting/verification.mjs +386 -0
- package/dist/finance/bizsim.d.mts +75 -0
- package/dist/finance/bizsim.mjs +296 -0
- package/dist/finance/index.d.mts +95 -0
- package/dist/finance/index.mjs +145 -0
- package/dist/finance/investment-math.d.mts +7 -0
- package/dist/finance/investment-math.mjs +18 -0
- package/dist/finance/management-accounting/budgeting.d.mts +7 -0
- package/dist/finance/management-accounting/budgeting.mjs +189 -0
- package/dist/finance/management-accounting/cash-budget.d.mts +7 -0
- package/dist/finance/management-accounting/cash-budget.mjs +154 -0
- package/dist/finance/management-accounting/costing.d.mts +8 -0
- package/dist/finance/management-accounting/costing.mjs +175 -0
- package/dist/finance/management-accounting/decisions.d.mts +8 -0
- package/dist/finance/management-accounting/decisions.mjs +164 -0
- package/dist/finance/management-accounting/index.d.mts +13 -0
- package/dist/finance/management-accounting/index.mjs +13 -0
- package/dist/finance/management-accounting/integrated-budget.d.mts +8 -0
- package/dist/finance/management-accounting/integrated-budget.mjs +67 -0
- package/dist/finance/management-accounting/inventory-costing.d.mts +7 -0
- package/dist/finance/management-accounting/inventory-costing.mjs +173 -0
- package/dist/finance/management-accounting/investment-appraisal.d.mts +7 -0
- package/dist/finance/management-accounting/investment-appraisal.mjs +148 -0
- package/dist/finance/management-accounting/management-case.d.mts +8 -0
- package/dist/finance/management-accounting/management-case.mjs +91 -0
- package/dist/finance/management-accounting/master-budget.d.mts +7 -0
- package/dist/finance/management-accounting/master-budget.mjs +137 -0
- package/dist/finance/management-accounting/production-costing.d.mts +8 -0
- package/dist/finance/management-accounting/production-costing.mjs +214 -0
- package/dist/finance/management-accounting/types.d.mts +644 -0
- package/dist/finance/management-accounting/variances.d.mts +7 -0
- package/dist/finance/management-accounting/variances.mjs +150 -0
- package/dist/index.d.mts +9 -8
- package/dist/index.mjs +5 -5
- package/dist/interaction/MovableDot.mjs +19 -0
- package/dist/interaction/useDraggable.mjs +24 -4
- package/dist/math/analysis.d.mts +61 -0
- package/dist/math/analysis.mjs +187 -0
- package/dist/math/answer-check.d.mts +50 -0
- package/dist/math/answer-check.mjs +106 -0
- package/dist/math/calculus.d.mts +17 -1
- package/dist/math/calculus.mjs +365 -2
- package/dist/math/complex.d.mts +93 -0
- package/dist/math/complex.mjs +239 -0
- package/dist/math/expr.d.mts +23 -0
- package/dist/math/expr.mjs +36 -0
- package/dist/math/index.d.mts +9 -23
- package/dist/math/index.mjs +9 -38
- package/dist/math/latex.mjs +10 -1
- package/dist/math/parse.mjs +1 -1
- package/dist/math/poly.d.mts +55 -0
- package/dist/math/poly.mjs +273 -0
- package/dist/math/rearrange.d.mts +14 -0
- package/dist/math/rearrange.mjs +125 -0
- package/dist/math/solve.d.mts +21 -0
- package/dist/math/solve.mjs +75 -0
- package/dist/networking/addressing.d.mts +26 -0
- package/dist/networking/addressing.mjs +33 -0
- package/dist/networking/cloud/access.d.mts +36 -0
- package/dist/networking/cloud/access.mjs +95 -0
- package/dist/networking/cloud/containers.d.mts +43 -0
- package/dist/networking/cloud/containers.mjs +54 -0
- package/dist/networking/cloud/edge.d.mts +17 -0
- package/dist/networking/cloud/edge.mjs +31 -0
- package/dist/networking/cloud/failure-domains.d.mts +19 -0
- package/dist/networking/cloud/failure-domains.mjs +22 -0
- package/dist/networking/cloud/geo-routing.d.mts +22 -0
- package/dist/networking/cloud/geo-routing.mjs +64 -0
- package/dist/networking/cloud/index.d.mts +18 -0
- package/dist/networking/cloud/index.mjs +19 -0
- package/dist/networking/cloud/inference-reliability.d.mts +30 -0
- package/dist/networking/cloud/inference-reliability.mjs +76 -0
- package/dist/networking/cloud/inference.d.mts +118 -0
- package/dist/networking/cloud/inference.mjs +179 -0
- package/dist/networking/cloud/infrastructure.d.mts +45 -0
- package/dist/networking/cloud/infrastructure.mjs +96 -0
- package/dist/networking/cloud/observability.d.mts +24 -0
- package/dist/networking/cloud/observability.mjs +34 -0
- package/dist/networking/cloud/orchestration.d.mts +32 -0
- package/dist/networking/cloud/orchestration.mjs +38 -0
- package/dist/networking/cloud/recovery.d.mts +21 -0
- package/dist/networking/cloud/recovery.mjs +27 -0
- package/dist/networking/cloud/releases.d.mts +42 -0
- package/dist/networking/cloud/releases.mjs +135 -0
- package/dist/networking/cloud/scaling.d.mts +25 -0
- package/dist/networking/cloud/scaling.mjs +65 -0
- package/dist/networking/cloud/secrets.d.mts +39 -0
- package/dist/networking/cloud/secrets.mjs +68 -0
- package/dist/networking/cloud/server-deployment.d.mts +29 -0
- package/dist/networking/cloud/server-deployment.mjs +72 -0
- package/dist/networking/cloud/storage.d.mts +16 -0
- package/dist/networking/cloud/storage.mjs +58 -0
- package/dist/networking/cloud/vpc.d.mts +18 -0
- package/dist/networking/cloud/vpc.mjs +100 -0
- package/dist/networking/delivery.d.mts +34 -0
- package/dist/networking/delivery.mjs +52 -0
- package/dist/networking/index.d.mts +47 -0
- package/dist/networking/index.mjs +47 -0
- package/dist/networking/ipv6.d.mts +28 -0
- package/dist/networking/ipv6.mjs +17 -0
- package/dist/networking/journeys.d.mts +83 -0
- package/dist/networking/journeys.mjs +161 -0
- package/dist/networking/models/airtime.d.mts +87 -0
- package/dist/networking/models/airtime.mjs +130 -0
- package/dist/networking/models/cellular.d.mts +157 -0
- package/dist/networking/models/cellular.mjs +252 -0
- package/dist/networking/models/encapsulation.d.mts +98 -0
- package/dist/networking/models/encapsulation.mjs +132 -0
- package/dist/networking/models/handover.d.mts +116 -0
- package/dist/networking/models/handover.mjs +209 -0
- package/dist/networking/models/handshake.d.mts +90 -0
- package/dist/networking/models/handshake.mjs +122 -0
- package/dist/networking/models/index.d.mts +14 -0
- package/dist/networking/models/index.mjs +15 -0
- package/dist/networking/models/media.d.mts +82 -0
- package/dist/networking/models/media.mjs +188 -0
- package/dist/networking/models/satellite.d.mts +86 -0
- package/dist/networking/models/satellite.mjs +121 -0
- package/dist/networking/models/spectrum.d.mts +83 -0
- package/dist/networking/models/spectrum.mjs +235 -0
- package/dist/networking/models/switch.d.mts +80 -0
- package/dist/networking/models/switch.mjs +155 -0
- package/dist/networking/models/vlan.d.mts +62 -0
- package/dist/networking/models/vlan.mjs +100 -0
- package/dist/networking/models/vpn.d.mts +66 -0
- package/dist/networking/models/vpn.mjs +125 -0
- package/dist/networking/models/wifi-privacy.d.mts +82 -0
- package/dist/networking/models/wifi-privacy.mjs +130 -0
- package/dist/networking/models/wifi.d.mts +240 -0
- package/dist/networking/models/wifi.mjs +562 -0
- package/dist/networking/nat-traversal.d.mts +24 -0
- package/dist/networking/nat-traversal.mjs +38 -0
- package/dist/networking/protocols.d.mts +17 -0
- package/dist/networking/protocols.mjs +57 -0
- package/dist/networking/queue.d.mts +12 -0
- package/dist/networking/queue.mjs +18 -0
- package/dist/networking/route-learning.d.mts +23 -0
- package/dist/networking/route-learning.mjs +43 -0
- package/dist/networking/routing.d.mts +11 -0
- package/dist/networking/routing.mjs +25 -0
- package/dist/networking/signals.d.mts +26 -0
- package/dist/networking/signals.mjs +35 -0
- package/dist/networking/subnet.d.mts +49 -0
- package/dist/networking/subnet.mjs +89 -0
- package/dist/networking/tcp-reliability.d.mts +24 -0
- package/dist/networking/tcp-reliability.mjs +38 -0
- package/dist/networking/topology/contract.d.mts +123 -0
- package/dist/networking/topology/index.d.mts +4 -0
- package/dist/networking/topology/index.mjs +4 -0
- package/dist/networking/topology/presets.d.mts +7 -0
- package/dist/networking/topology/presets.mjs +302 -0
- package/dist/networking/topology/simulation.d.mts +8 -0
- package/dist/networking/topology/simulation.mjs +179 -0
- package/dist/networking/wireless.d.mts +11 -0
- package/dist/networking/wireless.mjs +17 -0
- package/dist/optics/imaging.d.mts +218 -0
- package/dist/optics/imaging.mjs +276 -0
- package/dist/optics/index.d.mts +7 -0
- package/dist/optics/index.mjs +8 -0
- package/dist/optics/laws.d.mts +70 -0
- package/dist/optics/laws.mjs +195 -0
- package/dist/optics/prism.d.mts +148 -0
- package/dist/optics/prism.mjs +197 -0
- package/dist/optics/refraction.d.mts +201 -0
- package/dist/optics/refraction.mjs +270 -0
- package/dist/optics/wave-optics.d.mts +171 -0
- package/dist/optics/wave-optics.mjs +259 -0
- package/dist/physics/ac/index.d.mts +183 -0
- package/dist/physics/ac/index.mjs +203 -0
- package/dist/physics/dynamics/forces.d.mts +98 -0
- package/dist/physics/dynamics/forces.mjs +153 -0
- package/dist/physics/dynamics/friction.d.mts +76 -0
- package/dist/physics/dynamics/friction.mjs +119 -0
- package/dist/physics/dynamics/system.d.mts +68 -0
- package/dist/physics/dynamics/system.mjs +125 -0
- package/dist/physics/electrostatics/index.d.mts +169 -0
- package/dist/physics/electrostatics/index.mjs +249 -0
- package/dist/physics/energy/centre-of-mass.d.mts +115 -0
- package/dist/physics/energy/centre-of-mass.mjs +180 -0
- package/dist/physics/energy/conservation.d.mts +81 -0
- package/dist/physics/energy/conservation.mjs +129 -0
- package/dist/physics/energy/power.d.mts +90 -0
- package/dist/physics/energy/power.mjs +167 -0
- package/dist/physics/energy/spring.d.mts +73 -0
- package/dist/physics/energy/spring.mjs +129 -0
- package/dist/physics/energy/store.d.mts +63 -0
- package/dist/physics/energy/store.mjs +108 -0
- package/dist/physics/energy/theorem.d.mts +65 -0
- package/dist/physics/energy/theorem.mjs +113 -0
- package/dist/physics/energy/work.d.mts +114 -0
- package/dist/physics/energy/work.mjs +219 -0
- package/dist/physics/gravitation/body.d.mts +85 -0
- package/dist/physics/gravitation/body.mjs +168 -0
- package/dist/physics/gravitation/kepler.d.mts +127 -0
- package/dist/physics/gravitation/kepler.mjs +216 -0
- package/dist/physics/gravitation/law.d.mts +117 -0
- package/dist/physics/gravitation/law.mjs +175 -0
- package/dist/physics/gravitation/orbit.d.mts +119 -0
- package/dist/physics/gravitation/orbit.mjs +202 -0
- package/dist/physics/gravitation/potential.d.mts +114 -0
- package/dist/physics/gravitation/potential.mjs +202 -0
- package/dist/physics/gravitation/variation.d.mts +97 -0
- package/dist/physics/gravitation/variation.mjs +175 -0
- package/dist/physics/index.d.mts +35 -0
- package/dist/physics/index.mjs +36 -0
- package/dist/physics/integral-sweep.d.mts +63 -0
- package/dist/physics/integral-sweep.mjs +126 -0
- package/dist/physics/kinematics/equations.d.mts +47 -0
- package/dist/physics/kinematics/equations.mjs +126 -0
- package/dist/physics/kinematics/free-fall.d.mts +53 -0
- package/dist/physics/kinematics/free-fall.mjs +71 -0
- package/dist/physics/kinematics/given.d.mts +16 -0
- package/dist/physics/kinematics/given.mjs +55 -0
- package/dist/physics/kinematics/roots.d.mts +41 -0
- package/dist/physics/kinematics/roots.mjs +72 -0
- package/dist/physics/kinematics/solve.d.mts +52 -0
- package/dist/physics/kinematics/solve.mjs +172 -0
- package/dist/physics/magnetism/biot-savart.d.mts +161 -0
- package/dist/physics/magnetism/biot-savart.mjs +353 -0
- package/dist/physics/magnetism/flux.d.mts +94 -0
- package/dist/physics/magnetism/flux.mjs +313 -0
- package/dist/physics/magnetism/geomagnetism.d.mts +151 -0
- package/dist/physics/magnetism/geomagnetism.mjs +184 -0
- package/dist/physics/magnetism/index.d.mts +12 -0
- package/dist/physics/magnetism/index.mjs +74 -0
- package/dist/physics/magnetism/lorentz.d.mts +28 -0
- package/dist/physics/magnetism/lorentz.mjs +88 -0
- package/dist/physics/magnetism/magnetic-force.d.mts +102 -0
- package/dist/physics/magnetism/magnetic-force.mjs +169 -0
- package/dist/physics/momentum/collide.d.mts +77 -0
- package/dist/physics/momentum/collide.mjs +115 -0
- package/dist/physics/momentum/impulse.d.mts +89 -0
- package/dist/physics/momentum/impulse.mjs +159 -0
- package/dist/physics/momentum/planar.d.mts +60 -0
- package/dist/physics/momentum/planar.mjs +110 -0
- package/dist/physics/projectile.d.mts +107 -0
- package/dist/physics/projectile.mjs +185 -0
- package/dist/physics/rotation/angular.d.mts +85 -0
- package/dist/physics/rotation/angular.mjs +130 -0
- package/dist/physics/rotation/circular.d.mts +79 -0
- package/dist/physics/rotation/circular.mjs +131 -0
- package/dist/physics/rotation/inertia.d.mts +164 -0
- package/dist/physics/rotation/inertia.mjs +332 -0
- package/dist/physics/rotation/torque.d.mts +65 -0
- package/dist/physics/rotation/torque.mjs +134 -0
- package/dist/physics/vectors.d.mts +64 -0
- package/dist/physics/vectors.mjs +114 -0
- package/dist/primitives/Dot.d.mts +2 -15
- package/dist/primitives/Dot.mjs +6 -4
- package/dist/primitives/Grid.d.mts +33 -17
- package/dist/primitives/Grid.mjs +89 -17
- package/dist/primitives/Label.d.mts +1 -14
- package/dist/primitives/Label.mjs +3 -2
- package/dist/primitives/Lines.d.mts +4 -32
- package/dist/primitives/Lines.mjs +10 -8
- package/dist/primitives/Shapes.d.mts +5 -43
- package/dist/primitives/Shapes.mjs +12 -10
- package/dist/primitives/index.d.mts +2 -2
- package/dist/primitives/index.mjs +2 -2
- package/dist/primitives/props.mjs +31 -0
- package/dist/quantity/index.d.mts +119 -0
- package/dist/quantity/index.mjs +417 -0
- package/dist/relation/derive.d.mts +74 -0
- package/dist/relation/derive.mjs +73 -0
- package/dist/relation/index.d.mts +56 -0
- package/dist/relation/index.mjs +234 -0
- package/dist/scene/Scene.d.mts +6 -1
- package/dist/scene/Scene.mjs +15 -40
- package/dist/scene/evaluators.mjs +1 -1
- package/dist/sim/thermal.mjs +45 -20
- package/dist/thermo/calorimetry.d.mts +207 -0
- package/dist/thermo/calorimetry.mjs +345 -0
- package/dist/thermo/cycles.d.mts +142 -0
- package/dist/thermo/cycles.mjs +256 -0
- package/dist/thermo/entropy.d.mts +87 -0
- package/dist/thermo/entropy.mjs +140 -0
- package/dist/thermo/expansion.d.mts +130 -0
- package/dist/thermo/expansion.mjs +178 -0
- package/dist/thermo/gas.d.mts +197 -0
- package/dist/thermo/gas.mjs +279 -0
- package/dist/thermo/heat-transfer.d.mts +164 -0
- package/dist/thermo/heat-transfer.mjs +217 -0
- package/dist/thermo/index.d.mts +9 -82
- package/dist/thermo/index.mjs +9 -132
- package/dist/thermo/processes.d.mts +95 -0
- package/dist/thermo/processes.mjs +154 -0
- package/dist/thermo/temperature.d.mts +174 -0
- package/dist/thermo/temperature.mjs +236 -0
- package/dist/view/Stage.mjs +4 -11
- package/dist/waves/damping.d.mts +224 -0
- package/dist/waves/damping.mjs +317 -0
- package/dist/waves/doppler.d.mts +72 -0
- package/dist/waves/doppler.mjs +125 -0
- package/dist/waves/index.d.mts +10 -0
- package/dist/waves/index.mjs +10 -0
- package/dist/waves/pendulum.d.mts +130 -0
- package/dist/waves/pendulum.mjs +211 -0
- package/dist/waves/pitch.d.mts +125 -0
- package/dist/waves/pitch.mjs +158 -0
- package/dist/waves/shm.d.mts +170 -0
- package/dist/waves/shm.mjs +279 -0
- package/dist/waves/springs.d.mts +103 -0
- package/dist/waves/springs.mjs +176 -0
- package/dist/waves/superposition.d.mts +124 -0
- package/dist/waves/superposition.mjs +196 -0
- package/dist/waves/wave.d.mts +154 -0
- package/dist/waves/wave.mjs +178 -0
- package/package.json +103 -23
- package/styles.css +125 -8
- package/dist/assets/kit/index.mjs +0 -4
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { DEFAULT_ACCOUNTING_POLICY, fromMinor, toMinor } from "./precision.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/finance/accounting/partnership.ts
|
|
4
|
+
function solvePartnershipAppropriation(agreement, partners, policy = DEFAULT_ACCOUNTING_POLICY) {
|
|
5
|
+
const diagnostics = [];
|
|
6
|
+
if ([
|
|
7
|
+
agreement.profit,
|
|
8
|
+
agreement.interestOnCapitalPct,
|
|
9
|
+
agreement.interestOnDrawingsPct,
|
|
10
|
+
...partners.flatMap((partner) => [
|
|
11
|
+
partner.capital,
|
|
12
|
+
partner.drawings,
|
|
13
|
+
partner.salary,
|
|
14
|
+
partner.share,
|
|
15
|
+
partner.openingCurrentBalance ?? 0
|
|
16
|
+
])
|
|
17
|
+
].some((value) => !Number.isFinite(value) || value < 0)) diagnostics.push({
|
|
18
|
+
code: "invalid-adjustment",
|
|
19
|
+
severity: "error",
|
|
20
|
+
message: "Partnership amounts, rates and share units must be finite non-negative values."
|
|
21
|
+
});
|
|
22
|
+
if (partners.length < 2) diagnostics.push({
|
|
23
|
+
code: "invalid-adjustment",
|
|
24
|
+
severity: "error",
|
|
25
|
+
message: "A partnership requires at least two partners."
|
|
26
|
+
});
|
|
27
|
+
if (partners.some((partner) => partner.share <= 0)) diagnostics.push({
|
|
28
|
+
code: "invalid-adjustment",
|
|
29
|
+
severity: "error",
|
|
30
|
+
message: "Every partner needs a positive profit-sharing unit."
|
|
31
|
+
});
|
|
32
|
+
if (new Set(partners.map((partner) => partner.id)).size !== partners.length) diagnostics.push({
|
|
33
|
+
code: "invalid-adjustment",
|
|
34
|
+
severity: "error",
|
|
35
|
+
message: "Partner ids must be unique."
|
|
36
|
+
});
|
|
37
|
+
const empty = {
|
|
38
|
+
totalInterestOnCapital: 0,
|
|
39
|
+
totalSalaries: 0,
|
|
40
|
+
totalInterestOnDrawings: 0,
|
|
41
|
+
residualProfit: 0,
|
|
42
|
+
partners: [],
|
|
43
|
+
spread: 0,
|
|
44
|
+
appropriatesExactly: false,
|
|
45
|
+
diagnostics,
|
|
46
|
+
trace: []
|
|
47
|
+
};
|
|
48
|
+
if (diagnostics.length > 0) return empty;
|
|
49
|
+
const m = (value) => toMinor(value, policy);
|
|
50
|
+
const out = (value) => fromMinor(value, policy);
|
|
51
|
+
const interestCapital = partners.map((partner) => Math.round(m(partner.capital) * agreement.interestOnCapitalPct / 100));
|
|
52
|
+
const interestDrawings = partners.map((partner) => Math.round(m(partner.drawings) * agreement.interestOnDrawingsPct / 100));
|
|
53
|
+
const salaries = partners.map((partner) => m(partner.salary));
|
|
54
|
+
const totalInterestOnCapital = interestCapital.reduce((sum, value) => sum + value, 0);
|
|
55
|
+
const totalInterestOnDrawings = interestDrawings.reduce((sum, value) => sum + value, 0);
|
|
56
|
+
const totalSalaries = salaries.reduce((sum, value) => sum + value, 0);
|
|
57
|
+
const residual = m(agreement.profit) - totalInterestOnCapital - totalSalaries + totalInterestOnDrawings;
|
|
58
|
+
const totalUnits = partners.reduce((sum, partner) => sum + partner.share, 0);
|
|
59
|
+
let allocated = 0;
|
|
60
|
+
const residualShares = partners.map((partner, index) => {
|
|
61
|
+
const share = index === partners.length - 1 ? residual - allocated : Math.round(residual * partner.share / totalUnits);
|
|
62
|
+
allocated += share;
|
|
63
|
+
return share;
|
|
64
|
+
});
|
|
65
|
+
const solvedPartners = partners.map((partner, index) => {
|
|
66
|
+
const ioc = interestCapital[index], iod = interestDrawings[index], salary = salaries[index], share = residualShares[index];
|
|
67
|
+
const opening = m(partner.openingCurrentBalance ?? 0) * (partner.openingCurrentSide === "debit" ? -1 : 1);
|
|
68
|
+
const credits = ioc + salary + share;
|
|
69
|
+
const debits = m(partner.drawings) + iod;
|
|
70
|
+
const closing = opening + credits - debits;
|
|
71
|
+
const movements = [
|
|
72
|
+
{
|
|
73
|
+
label: "Opening balance",
|
|
74
|
+
side: partner.openingCurrentSide ?? "credit",
|
|
75
|
+
amount: out(Math.abs(opening))
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
label: "Interest on capital",
|
|
79
|
+
side: "credit",
|
|
80
|
+
amount: out(ioc)
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
label: "Partner salary",
|
|
84
|
+
side: "credit",
|
|
85
|
+
amount: out(salary)
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
label: "Share of residual profit",
|
|
89
|
+
side: "credit",
|
|
90
|
+
amount: out(share)
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
label: "Drawings",
|
|
94
|
+
side: "debit",
|
|
95
|
+
amount: partner.drawings
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
label: "Interest on drawings",
|
|
99
|
+
side: "debit",
|
|
100
|
+
amount: out(iod)
|
|
101
|
+
}
|
|
102
|
+
].filter((movement) => movement.amount !== 0);
|
|
103
|
+
return {
|
|
104
|
+
id: partner.id,
|
|
105
|
+
name: partner.name,
|
|
106
|
+
interestOnCapital: out(ioc),
|
|
107
|
+
salary: out(salary),
|
|
108
|
+
interestOnDrawings: out(iod),
|
|
109
|
+
shareOfResidual: out(share),
|
|
110
|
+
totalAppropriation: out(ioc + salary + share - iod),
|
|
111
|
+
currentAccountMovements: movements,
|
|
112
|
+
closingCurrentBalance: out(Math.abs(closing)),
|
|
113
|
+
closingCurrentSide: closing === 0 ? "zero" : closing > 0 ? "credit" : "debit"
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
const totals = solvedPartners.map((partner) => m(partner.totalAppropriation));
|
|
117
|
+
const appropriated = totals.reduce((sum, value) => sum + value, 0);
|
|
118
|
+
const spread = Math.max(...totals) - Math.min(...totals);
|
|
119
|
+
return {
|
|
120
|
+
totalInterestOnCapital: out(totalInterestOnCapital),
|
|
121
|
+
totalSalaries: out(totalSalaries),
|
|
122
|
+
totalInterestOnDrawings: out(totalInterestOnDrawings),
|
|
123
|
+
residualProfit: out(residual),
|
|
124
|
+
partners: solvedPartners,
|
|
125
|
+
spread: out(spread),
|
|
126
|
+
appropriatesExactly: appropriated === m(agreement.profit),
|
|
127
|
+
diagnostics,
|
|
128
|
+
trace: [{
|
|
129
|
+
id: "partnership:residual",
|
|
130
|
+
kind: "derive",
|
|
131
|
+
rule: "Residual profit = profit − interest on capital − salaries + interest on drawings.",
|
|
132
|
+
working: `${agreement.profit} − ${out(totalInterestOnCapital)} − ${out(totalSalaries)} + ${out(totalInterestOnDrawings)}`,
|
|
133
|
+
result: out(residual)
|
|
134
|
+
}, {
|
|
135
|
+
id: "partnership:allocation",
|
|
136
|
+
kind: "check",
|
|
137
|
+
rule: "Appropriation redistributes the profit; it does not create or remove profit.",
|
|
138
|
+
working: `${out(appropriated)} compared with ${agreement.profit}`,
|
|
139
|
+
result: appropriated === m(agreement.profit)
|
|
140
|
+
}]
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function salaryForEqualPartnershipShares(agreement, partners, policy = DEFAULT_ACCOUNTING_POLICY) {
|
|
144
|
+
if (partners.length !== 2 || partners[0].share !== partners[1].share) return null;
|
|
145
|
+
const own = (partner) => partner.capital * agreement.interestOnCapitalPct / 100 - partner.drawings * agreement.interestOnDrawingsPct / 100;
|
|
146
|
+
const salaried = partners[1].salary > 0 || partners[0].salary === 0 ? partners[1] : partners[0];
|
|
147
|
+
const other = salaried === partners[1] ? partners[0] : partners[1];
|
|
148
|
+
return fromMinor(toMinor(Math.max(0, own(other) - own(salaried)), policy), policy);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
export { salaryForEqualPartnershipShares, solvePartnershipAppropriation };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AccountingPolicy, SoleTraderPeriodCase, SoleTraderPeriodResult } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/finance/accounting/period-case.d.ts
|
|
4
|
+
declare function solveSoleTraderPeriod(period: SoleTraderPeriodCase, policy?: AccountingPolicy): SoleTraderPeriodResult;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { solveSoleTraderPeriod };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { DEFAULT_ACCOUNTING_POLICY, fromMinor, toMinor } from "./precision.mjs";
|
|
2
|
+
import { solveJournal } from "./solve.mjs";
|
|
3
|
+
import { produceAdjustment } from "./adjustments.mjs";
|
|
4
|
+
import { solveSoleTraderStatements } from "./statements.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/finance/accounting/period-case.ts
|
|
7
|
+
function sum(ledger, policy, predicate) {
|
|
8
|
+
return fromMinor(ledger.filter(predicate).reduce((total, account) => total + toMinor(account.normalBalance, policy), 0), policy);
|
|
9
|
+
}
|
|
10
|
+
function solveSoleTraderPeriod(period, policy = DEFAULT_ACCOUNTING_POLICY) {
|
|
11
|
+
const unadjusted = solveJournal({
|
|
12
|
+
accounts: period.accounts,
|
|
13
|
+
entries: period.unadjustedEntries,
|
|
14
|
+
policy
|
|
15
|
+
});
|
|
16
|
+
const adjustmentResults = period.adjustments.map((fact) => produceAdjustment(fact, policy));
|
|
17
|
+
const adjustmentDiagnostics = adjustmentResults.flatMap((result) => result.diagnostics);
|
|
18
|
+
const adjustmentTrace = adjustmentResults.flatMap((result) => result.trace);
|
|
19
|
+
const adjusted = solveJournal({
|
|
20
|
+
accounts: period.accounts,
|
|
21
|
+
entries: [...period.unadjustedEntries, ...adjustmentResults.flatMap((result) => result.entries)],
|
|
22
|
+
policy,
|
|
23
|
+
initialDiagnostics: adjustmentDiagnostics,
|
|
24
|
+
trace: adjustmentTrace
|
|
25
|
+
});
|
|
26
|
+
const ledger = adjusted.ledger;
|
|
27
|
+
const revenue = sum(ledger, policy, (account) => account.role === "revenue");
|
|
28
|
+
const costOfSales = sum(ledger, policy, (account) => account.role === "cost-of-sales");
|
|
29
|
+
const expenses = sum(ledger, policy, (account) => account.category === "Expense" && account.role !== "cost-of-sales");
|
|
30
|
+
const nonCurrentAssets = sum(ledger, policy, (account) => account.role === "equipment");
|
|
31
|
+
const inventory = sum(ledger, policy, (account) => account.role === "inventory");
|
|
32
|
+
const cash = sum(ledger, policy, (account) => account.role === "cash" || account.role === "bank");
|
|
33
|
+
const otherCurrentAssets = sum(ledger, policy, (account) => account.category === "Asset" && account.role !== "equipment" && account.role !== "inventory" && account.role !== "cash" && account.role !== "bank");
|
|
34
|
+
const openingCapital = sum(ledger, policy, (account) => account.role === "capital");
|
|
35
|
+
const drawings = -sum(ledger, policy, (account) => account.role === "drawings");
|
|
36
|
+
const loan = sum(ledger, policy, (account) => account.role === "loan");
|
|
37
|
+
const currentLiabilities = sum(ledger, policy, (account) => account.category === "Liability" && account.role !== "loan");
|
|
38
|
+
const missingRoles = ["revenue", "capital"].flatMap((role) => !period.accounts.some((account) => account.role === role) ? [{
|
|
39
|
+
code: "missing-role",
|
|
40
|
+
severity: "error",
|
|
41
|
+
message: `The period case requires a non-zero ${role} account role.`
|
|
42
|
+
}] : []);
|
|
43
|
+
const statements = solveSoleTraderStatements({
|
|
44
|
+
revenue,
|
|
45
|
+
costOfSales,
|
|
46
|
+
expenses,
|
|
47
|
+
nonCurrentAssets,
|
|
48
|
+
inventory,
|
|
49
|
+
cash,
|
|
50
|
+
otherCurrentAssets,
|
|
51
|
+
openingCapital,
|
|
52
|
+
drawings,
|
|
53
|
+
loan,
|
|
54
|
+
currentLiabilities
|
|
55
|
+
}, policy);
|
|
56
|
+
return {
|
|
57
|
+
unadjusted,
|
|
58
|
+
adjustmentResults,
|
|
59
|
+
adjusted,
|
|
60
|
+
statements,
|
|
61
|
+
diagnostics: [
|
|
62
|
+
...adjusted.diagnostics,
|
|
63
|
+
...missingRoles,
|
|
64
|
+
...statements.diagnostics
|
|
65
|
+
],
|
|
66
|
+
trace: [...adjusted.trace, ...statements.trace]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { solveSoleTraderPeriod };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AccountDefinition, AccountingEquation, AccountingPolicy, FinancialStatements, JournalEntry, LedgerAccount, TrialBalance } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/finance/accounting/post.d.ts
|
|
4
|
+
declare function postLedger(accounts: readonly AccountDefinition[], entries: readonly JournalEntry[], policy: AccountingPolicy): LedgerAccount[];
|
|
5
|
+
declare function deriveTrialBalance(ledger: readonly LedgerAccount[], policy: AccountingPolicy): TrialBalance;
|
|
6
|
+
declare function deriveEquation(ledger: readonly LedgerAccount[], policy: AccountingPolicy): AccountingEquation;
|
|
7
|
+
declare function deriveStatements(equation: AccountingEquation): FinancialStatements;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { deriveEquation, deriveStatements, deriveTrialBalance, postLedger };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { fromMinor, toMinor } from "./precision.mjs";
|
|
2
|
+
import { normalBalance } from "./rules.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/finance/accounting/post.ts
|
|
5
|
+
function postLedger(accounts, entries, policy) {
|
|
6
|
+
return accounts.map((account) => {
|
|
7
|
+
const postings = [];
|
|
8
|
+
for (const entry of entries) {
|
|
9
|
+
const contras = entry.lines.filter((line) => line.accountId !== account.id).map((line) => line.accountId);
|
|
10
|
+
for (const line of entry.lines.filter((item) => item.accountId === account.id)) postings.push({
|
|
11
|
+
entryId: entry.id,
|
|
12
|
+
contraAccountIds: contras,
|
|
13
|
+
side: line.side,
|
|
14
|
+
amount: fromMinor(toMinor(line.amount, policy), policy),
|
|
15
|
+
narration: entry.narration
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
const debitMinor = postings.filter((posting) => posting.side === "debit").reduce((sum, posting) => sum + toMinor(posting.amount, policy), 0);
|
|
19
|
+
const creditMinor = postings.filter((posting) => posting.side === "credit").reduce((sum, posting) => sum + toMinor(posting.amount, policy), 0);
|
|
20
|
+
const netMinor = debitMinor - creditMinor;
|
|
21
|
+
const side = netMinor > 0 ? "debit" : netMinor < 0 ? "credit" : "zero";
|
|
22
|
+
const naturalMinor = netMinor === 0 ? 0 : normalBalance(account.category) === "debit" ? netMinor : -netMinor;
|
|
23
|
+
return {
|
|
24
|
+
...account,
|
|
25
|
+
postings,
|
|
26
|
+
debitTotal: fromMinor(debitMinor, policy),
|
|
27
|
+
creditTotal: fromMinor(creditMinor, policy),
|
|
28
|
+
balance: fromMinor(Math.abs(netMinor), policy),
|
|
29
|
+
balanceSide: side,
|
|
30
|
+
normalBalance: fromMinor(naturalMinor, policy)
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function deriveTrialBalance(ledger, policy) {
|
|
35
|
+
const lines = ledger.filter((account) => account.balanceSide !== "zero").map((account) => ({
|
|
36
|
+
accountId: account.id,
|
|
37
|
+
name: account.name,
|
|
38
|
+
debit: account.balanceSide === "debit" ? account.balance : 0,
|
|
39
|
+
credit: account.balanceSide === "credit" ? account.balance : 0
|
|
40
|
+
}));
|
|
41
|
+
const debitMinor = lines.reduce((sum, line) => sum + toMinor(line.debit, policy), 0);
|
|
42
|
+
const creditMinor = lines.reduce((sum, line) => sum + toMinor(line.credit, policy), 0);
|
|
43
|
+
return {
|
|
44
|
+
lines,
|
|
45
|
+
debitTotal: fromMinor(debitMinor, policy),
|
|
46
|
+
creditTotal: fromMinor(creditMinor, policy),
|
|
47
|
+
balances: debitMinor === creditMinor
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function deriveEquation(ledger, policy) {
|
|
51
|
+
const total = (category) => ledger.filter((account) => account.category === category).reduce((sum, account) => sum + toMinor(account.normalBalance, policy), 0);
|
|
52
|
+
const assetsMinor = total("Asset"), liabilitiesMinor = total("Liability"), equityBaseMinor = total("Equity"), incomeMinor = total("Income"), expensesMinor = total("Expense");
|
|
53
|
+
const profitMinor = incomeMinor - expensesMinor, equityMinor = equityBaseMinor + profitMinor;
|
|
54
|
+
return {
|
|
55
|
+
assets: fromMinor(assetsMinor, policy),
|
|
56
|
+
liabilities: fromMinor(liabilitiesMinor, policy),
|
|
57
|
+
contributedEquity: fromMinor(equityBaseMinor, policy),
|
|
58
|
+
income: fromMinor(incomeMinor, policy),
|
|
59
|
+
expenses: fromMinor(expensesMinor, policy),
|
|
60
|
+
profit: fromMinor(profitMinor, policy),
|
|
61
|
+
equity: fromMinor(equityMinor, policy),
|
|
62
|
+
left: fromMinor(assetsMinor, policy),
|
|
63
|
+
right: fromMinor(liabilitiesMinor + equityMinor, policy),
|
|
64
|
+
balances: assetsMinor === liabilitiesMinor + equityMinor
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function deriveStatements(equation) {
|
|
68
|
+
return {
|
|
69
|
+
incomeStatement: {
|
|
70
|
+
income: equation.income,
|
|
71
|
+
expenses: equation.expenses,
|
|
72
|
+
profit: equation.profit
|
|
73
|
+
},
|
|
74
|
+
statementOfFinancialPosition: {
|
|
75
|
+
assets: equation.assets,
|
|
76
|
+
liabilities: equation.liabilities,
|
|
77
|
+
equity: equation.equity,
|
|
78
|
+
balances: equation.balances
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
export { deriveEquation, deriveStatements, deriveTrialBalance, postLedger };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AccountingPolicy } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/finance/accounting/precision.d.ts
|
|
4
|
+
declare const DEFAULT_ACCOUNTING_POLICY: AccountingPolicy;
|
|
5
|
+
declare function amountScale(policy?: AccountingPolicy): number;
|
|
6
|
+
declare function toMinor(amount: number, policy?: AccountingPolicy): number;
|
|
7
|
+
declare function fromMinor(amount: number, policy?: AccountingPolicy): number;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { DEFAULT_ACCOUNTING_POLICY, amountScale, fromMinor, toMinor };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/finance/accounting/precision.ts
|
|
2
|
+
const DEFAULT_ACCOUNTING_POLICY = { decimalPlaces: 2 };
|
|
3
|
+
function amountScale(policy = DEFAULT_ACCOUNTING_POLICY) {
|
|
4
|
+
if (!Number.isInteger(policy.decimalPlaces) || policy.decimalPlaces < 0 || policy.decimalPlaces > 6) throw new Error("decimalPlaces must be an integer from 0 to 6");
|
|
5
|
+
return 10 ** policy.decimalPlaces;
|
|
6
|
+
}
|
|
7
|
+
function toMinor(amount, policy = DEFAULT_ACCOUNTING_POLICY) {
|
|
8
|
+
return Math.round(amount * amountScale(policy));
|
|
9
|
+
}
|
|
10
|
+
function fromMinor(amount, policy = DEFAULT_ACCOUNTING_POLICY) {
|
|
11
|
+
return amount / amountScale(policy);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { DEFAULT_ACCOUNTING_POLICY, amountScale, fromMinor, toMinor };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AccountCategory, PostingSide } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/finance/accounting/rules.d.ts
|
|
4
|
+
declare function normalBalance(category: AccountCategory): PostingSide;
|
|
5
|
+
declare function statementOf(category: AccountCategory): 'financial-position' | 'income';
|
|
6
|
+
declare function changeSide(category: AccountCategory, change: 'increase' | 'decrease'): PostingSide;
|
|
7
|
+
declare function totalsBalance(lines: ReadonlyArray<{
|
|
8
|
+
debit?: number;
|
|
9
|
+
credit?: number;
|
|
10
|
+
}>, tolerance?: number): boolean;
|
|
11
|
+
declare function deriveNaturalEquation(accounts: ReadonlyArray<{
|
|
12
|
+
id: string;
|
|
13
|
+
category: AccountCategory;
|
|
14
|
+
}>, balanceOf: (id: string) => number): {
|
|
15
|
+
assets: number;
|
|
16
|
+
liabilities: number;
|
|
17
|
+
equity: number;
|
|
18
|
+
profit: number;
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { changeSide, deriveNaturalEquation, normalBalance, statementOf, totalsBalance };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/finance/accounting/rules.ts
|
|
2
|
+
function normalBalance(category) {
|
|
3
|
+
return category === "Asset" || category === "Expense" ? "debit" : "credit";
|
|
4
|
+
}
|
|
5
|
+
function statementOf(category) {
|
|
6
|
+
return category === "Income" || category === "Expense" ? "income" : "financial-position";
|
|
7
|
+
}
|
|
8
|
+
function changeSide(category, change) {
|
|
9
|
+
const normal = normalBalance(category);
|
|
10
|
+
if (change === "increase") return normal;
|
|
11
|
+
return normal === "debit" ? "credit" : "debit";
|
|
12
|
+
}
|
|
13
|
+
function totalsBalance(lines, tolerance = .005) {
|
|
14
|
+
const debit = lines.reduce((sum, line) => sum + (line.debit ?? 0), 0);
|
|
15
|
+
const credit = lines.reduce((sum, line) => sum + (line.credit ?? 0), 0);
|
|
16
|
+
return Math.abs(debit - credit) < tolerance;
|
|
17
|
+
}
|
|
18
|
+
function deriveNaturalEquation(accounts, balanceOf) {
|
|
19
|
+
const totals = {
|
|
20
|
+
Asset: 0,
|
|
21
|
+
Liability: 0,
|
|
22
|
+
Equity: 0,
|
|
23
|
+
Income: 0,
|
|
24
|
+
Expense: 0
|
|
25
|
+
};
|
|
26
|
+
for (const account of accounts) totals[account.category] += balanceOf(account.id);
|
|
27
|
+
const profit = totals.Income - totals.Expense;
|
|
28
|
+
return {
|
|
29
|
+
assets: totals.Asset,
|
|
30
|
+
liabilities: totals.Liability,
|
|
31
|
+
equity: totals.Equity + profit,
|
|
32
|
+
profit
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { changeSide, deriveNaturalEquation, normalBalance, statementOf, totalsBalance };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AccountDefinition, AccountingDiagnostic, AccountingPolicy, AccountingSolution, BusinessEvent, ExplanationStep, JournalEntry } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/finance/accounting/solve.d.ts
|
|
4
|
+
interface SolveJournalOptions {
|
|
5
|
+
accounts: readonly AccountDefinition[];
|
|
6
|
+
entries: readonly JournalEntry[];
|
|
7
|
+
policy?: AccountingPolicy;
|
|
8
|
+
trace?: readonly ExplanationStep[];
|
|
9
|
+
initialDiagnostics?: readonly AccountingDiagnostic[];
|
|
10
|
+
}
|
|
11
|
+
declare function solveJournal({
|
|
12
|
+
accounts,
|
|
13
|
+
entries,
|
|
14
|
+
policy,
|
|
15
|
+
trace: initialTrace,
|
|
16
|
+
initialDiagnostics
|
|
17
|
+
}: SolveJournalOptions): AccountingSolution;
|
|
18
|
+
declare function solveBusinessProblem({
|
|
19
|
+
accounts,
|
|
20
|
+
events,
|
|
21
|
+
policy
|
|
22
|
+
}: {
|
|
23
|
+
accounts: readonly AccountDefinition[];
|
|
24
|
+
events: readonly BusinessEvent[];
|
|
25
|
+
policy?: AccountingPolicy;
|
|
26
|
+
}): AccountingSolution;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { SolveJournalOptions, solveBusinessProblem, solveJournal };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { journalizeBusinessEvents } from "./journalize.mjs";
|
|
2
|
+
import { DEFAULT_ACCOUNTING_POLICY } from "./precision.mjs";
|
|
3
|
+
import { deriveEquation, deriveStatements, deriveTrialBalance, postLedger } from "./post.mjs";
|
|
4
|
+
import { validateChart, validateJournalEntry } from "./validate.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/finance/accounting/solve.ts
|
|
7
|
+
function solveJournal({ accounts, entries, policy = DEFAULT_ACCOUNTING_POLICY, trace: initialTrace = [], initialDiagnostics = [] }) {
|
|
8
|
+
const chartDiagnostics = validateChart(accounts);
|
|
9
|
+
const diagnostics = [...initialDiagnostics, ...chartDiagnostics];
|
|
10
|
+
const trace = [...initialTrace];
|
|
11
|
+
const acceptedEntries = [], rejectedEntries = [];
|
|
12
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13
|
+
for (const entry of entries) {
|
|
14
|
+
const entryDiagnostics = validateJournalEntry(entry, accounts, policy);
|
|
15
|
+
if (chartDiagnostics.some((diagnostic) => diagnostic.severity === "error")) entryDiagnostics.push({
|
|
16
|
+
code: "duplicate-account",
|
|
17
|
+
severity: "error",
|
|
18
|
+
entryId: entry.id,
|
|
19
|
+
message: "The chart of accounts is invalid, so no journal can be posted."
|
|
20
|
+
});
|
|
21
|
+
if (seen.has(entry.id)) entryDiagnostics.push({
|
|
22
|
+
code: "duplicate-entry",
|
|
23
|
+
severity: "error",
|
|
24
|
+
entryId: entry.id,
|
|
25
|
+
message: `Entry ${entry.id} is declared more than once.`
|
|
26
|
+
});
|
|
27
|
+
seen.add(entry.id);
|
|
28
|
+
diagnostics.push(...entryDiagnostics);
|
|
29
|
+
const accepted = entryDiagnostics.every((diagnostic) => diagnostic.severity !== "error");
|
|
30
|
+
(accepted ? acceptedEntries : rejectedEntries).push(entry);
|
|
31
|
+
trace.push({
|
|
32
|
+
id: `${entry.id}:validate`,
|
|
33
|
+
kind: "validate",
|
|
34
|
+
rule: "A postable journal needs known accounts, positive amounts and equal debit and credit totals.",
|
|
35
|
+
working: `${entry.lines.length} line(s) checked`,
|
|
36
|
+
result: accepted ? "accepted" : "rejected"
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const ledger = postLedger(accounts, acceptedEntries, policy);
|
|
40
|
+
for (const account of ledger.filter((item) => item.postings.length > 0)) trace.push({
|
|
41
|
+
id: `${account.id}:post`,
|
|
42
|
+
kind: "post",
|
|
43
|
+
rule: "Post each journal line to its named ledger account.",
|
|
44
|
+
working: `${account.debitTotal} debit − ${account.creditTotal} credit`,
|
|
45
|
+
result: `${account.balance} ${account.balanceSide}`
|
|
46
|
+
});
|
|
47
|
+
const trialBalance = deriveTrialBalance(ledger, policy);
|
|
48
|
+
const equation = deriveEquation(ledger, policy);
|
|
49
|
+
const statements = deriveStatements(equation);
|
|
50
|
+
trace.push({
|
|
51
|
+
id: "trial-balance",
|
|
52
|
+
kind: "check",
|
|
53
|
+
rule: "A trial balance compares closing debit and credit balances.",
|
|
54
|
+
working: `${trialBalance.debitTotal} = ${trialBalance.creditTotal}`,
|
|
55
|
+
result: trialBalance.balances
|
|
56
|
+
}, {
|
|
57
|
+
id: "profit",
|
|
58
|
+
kind: "derive",
|
|
59
|
+
rule: "Profit = income − expenses.",
|
|
60
|
+
working: `${equation.income} − ${equation.expenses}`,
|
|
61
|
+
result: equation.profit
|
|
62
|
+
}, {
|
|
63
|
+
id: "equation",
|
|
64
|
+
kind: "check",
|
|
65
|
+
rule: "Assets = liabilities + equity, including current-period profit.",
|
|
66
|
+
working: `${equation.left} = ${equation.liabilities} + ${equation.equity}`,
|
|
67
|
+
result: equation.balances
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
acceptedEntries,
|
|
71
|
+
rejectedEntries,
|
|
72
|
+
diagnostics,
|
|
73
|
+
ledger,
|
|
74
|
+
trialBalance,
|
|
75
|
+
equation,
|
|
76
|
+
statements,
|
|
77
|
+
trace
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function solveBusinessProblem({ accounts, events, policy = DEFAULT_ACCOUNTING_POLICY }) {
|
|
81
|
+
const journalized = journalizeBusinessEvents(events, accounts);
|
|
82
|
+
return solveJournal({
|
|
83
|
+
accounts,
|
|
84
|
+
entries: journalized.entries,
|
|
85
|
+
policy,
|
|
86
|
+
trace: journalized.trace,
|
|
87
|
+
initialDiagnostics: journalized.diagnostics
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
export { solveBusinessProblem, solveJournal };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AccountingPolicy, SoleTraderStatementFacts, SoleTraderStatementResult } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/finance/accounting/statements.d.ts
|
|
4
|
+
declare function solveSoleTraderStatements(facts: SoleTraderStatementFacts, policy?: AccountingPolicy): SoleTraderStatementResult;
|
|
5
|
+
declare function solveCashSettledSoleTraderScenario(base: SoleTraderStatementFacts, trading: Pick<SoleTraderStatementFacts, 'revenue' | 'costOfSales' | 'expenses'>, policy?: AccountingPolicy): SoleTraderStatementResult;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { solveCashSettledSoleTraderScenario, solveSoleTraderStatements };
|