@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.
Files changed (458) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +5 -1
  3. package/dist/_virtual/_rolldown/runtime.mjs +18 -0
  4. package/dist/assets/index.mjs +0 -1
  5. package/dist/atomic/aufbau.d.mts +144 -0
  6. package/dist/atomic/aufbau.mjs +384 -0
  7. package/dist/atomic/elements.d.mts +67 -0
  8. package/dist/atomic/elements.mjs +785 -0
  9. package/dist/atomic/emission.d.mts +112 -0
  10. package/dist/atomic/emission.mjs +179 -0
  11. package/dist/atomic/index.d.mts +8 -0
  12. package/dist/atomic/index.mjs +9 -0
  13. package/dist/atomic/periodic.d.mts +82 -0
  14. package/dist/atomic/periodic.mjs +231 -0
  15. package/dist/atomic/properties.d.mts +100 -0
  16. package/dist/atomic/properties.mjs +574 -0
  17. package/dist/atomic/shells.d.mts +137 -0
  18. package/dist/atomic/shells.mjs +170 -0
  19. package/dist/atomic/trends.d.mts +148 -0
  20. package/dist/atomic/trends.mjs +225 -0
  21. package/dist/builder/Palette.mjs +50 -89
  22. package/dist/builder/SceneBuilder.mjs +15 -73
  23. package/dist/chem/chromatography.d.mts +66 -0
  24. package/dist/chem/chromatography.mjs +63 -0
  25. package/dist/chem/complex.d.mts +114 -0
  26. package/dist/chem/complex.mjs +234 -0
  27. package/dist/chem/cycle.d.mts +75 -0
  28. package/dist/chem/cycle.mjs +145 -0
  29. package/dist/chem/equation.d.mts +86 -0
  30. package/dist/chem/equation.mjs +168 -0
  31. package/dist/chem/formula.d.mts +90 -0
  32. package/dist/chem/formula.mjs +201 -0
  33. package/dist/chem/functional-groups.d.mts +31 -0
  34. package/dist/chem/functional-groups.mjs +187 -0
  35. package/dist/chem/hazard.d.mts +94 -0
  36. package/dist/chem/hazard.mjs +329 -0
  37. package/dist/chem/index.d.mts +34 -33
  38. package/dist/chem/index.mjs +34 -28
  39. package/dist/chem/ionic.d.mts +98 -0
  40. package/dist/chem/ionic.mjs +156 -0
  41. package/dist/chem/layout.d.mts +46 -0
  42. package/dist/chem/layout.mjs +342 -0
  43. package/dist/chem/lewis.d.mts +79 -0
  44. package/dist/chem/lewis.mjs +163 -0
  45. package/dist/chem/molecular-orbital.d.mts +114 -0
  46. package/dist/chem/molecular-orbital.mjs +201 -0
  47. package/dist/chem/molecule.d.mts +154 -0
  48. package/dist/chem/molecule.mjs +282 -0
  49. package/dist/chem/nmr.d.mts +153 -0
  50. package/dist/chem/nmr.mjs +165 -0
  51. package/dist/chem/polymer.d.mts +65 -0
  52. package/dist/chem/polymer.mjs +179 -0
  53. package/dist/chem/redox.d.mts +138 -0
  54. package/dist/chem/redox.mjs +328 -0
  55. package/dist/chem/relations.d.mts +183 -0
  56. package/dist/chem/relations.mjs +299 -0
  57. package/dist/chem/skeleton.d.mts +51 -0
  58. package/dist/chem/skeleton.mjs +186 -0
  59. package/dist/chem/solution.d.mts +116 -0
  60. package/dist/chem/solution.mjs +186 -0
  61. package/dist/chem/species.d.mts +47 -0
  62. package/dist/chem/species.mjs +128 -0
  63. package/dist/chem/stereo.d.mts +108 -0
  64. package/dist/chem/stereo.mjs +286 -0
  65. package/dist/chem/stoichiometry.d.mts +95 -0
  66. package/dist/chem/stoichiometry.mjs +145 -0
  67. package/dist/chem/synthesis.d.mts +113 -0
  68. package/dist/chem/synthesis.mjs +281 -0
  69. package/dist/chem/vsepr.d.mts +80 -0
  70. package/dist/chem/vsepr.mjs +247 -0
  71. package/dist/circuit/ac.d.mts +163 -0
  72. package/dist/circuit/ac.mjs +452 -0
  73. package/dist/circuit/dc.d.mts +92 -0
  74. package/dist/circuit/dc.mjs +333 -0
  75. package/dist/circuit/index.d.mts +5 -92
  76. package/dist/circuit/index.mjs +5 -332
  77. package/dist/circuit/network.d.mts +99 -0
  78. package/dist/circuit/network.mjs +440 -0
  79. package/dist/circuit/topology.d.mts +102 -0
  80. package/dist/circuit/topology.mjs +143 -0
  81. package/dist/colour/absorption.d.mts +79 -0
  82. package/dist/colour/absorption.mjs +137 -0
  83. package/dist/colour/index.d.mts +6 -0
  84. package/dist/colour/index.mjs +7 -0
  85. package/dist/colour/name.d.mts +14 -0
  86. package/dist/colour/name.mjs +76 -0
  87. package/dist/colour/observer.d.mts +31 -0
  88. package/dist/colour/observer.mjs +46 -0
  89. package/dist/colour/spectrum.d.mts +61 -0
  90. package/dist/colour/spectrum.mjs +108 -0
  91. package/dist/colour/srgb.d.mts +49 -0
  92. package/dist/colour/srgb.mjs +108 -0
  93. package/dist/core/constants.d.mts +138 -0
  94. package/dist/core/constants.mjs +139 -0
  95. package/dist/core/index.d.mts +4 -1
  96. package/dist/core/index.mjs +4 -1
  97. package/dist/core/math.d.mts +26 -0
  98. package/dist/core/math.mjs +37 -0
  99. package/dist/core/vec3.d.mts +94 -0
  100. package/dist/core/vec3.mjs +123 -0
  101. package/dist/core/worked.d.mts +35 -0
  102. package/dist/core/worked.mjs +44 -0
  103. package/dist/electro/cell.d.mts +102 -0
  104. package/dist/electro/cell.mjs +170 -0
  105. package/dist/electro/conductivity.d.mts +157 -0
  106. package/dist/electro/conductivity.mjs +156 -0
  107. package/dist/electro/couples.d.mts +114 -0
  108. package/dist/electro/couples.mjs +334 -0
  109. package/dist/electro/electrolysis.d.mts +96 -0
  110. package/dist/electro/electrolysis.mjs +274 -0
  111. package/dist/electro/faraday.d.mts +150 -0
  112. package/dist/electro/faraday.mjs +118 -0
  113. package/dist/electro/index.d.mts +6 -0
  114. package/dist/electro/index.mjs +7 -0
  115. package/dist/finance/accounting/adjustments.d.mts +17 -0
  116. package/dist/finance/accounting/adjustments.mjs +202 -0
  117. package/dist/finance/accounting/analysis.d.mts +8 -0
  118. package/dist/finance/accounting/analysis.mjs +205 -0
  119. package/dist/finance/accounting/clubs.d.mts +21 -0
  120. package/dist/finance/accounting/clubs.mjs +217 -0
  121. package/dist/finance/accounting/company-statements.d.mts +7 -0
  122. package/dist/finance/accounting/company-statements.mjs +150 -0
  123. package/dist/finance/accounting/harness.d.mts +7 -0
  124. package/dist/finance/accounting/harness.mjs +45 -0
  125. package/dist/finance/accounting/index.d.mts +18 -0
  126. package/dist/finance/accounting/index.mjs +18 -0
  127. package/dist/finance/accounting/journalize.d.mts +16 -0
  128. package/dist/finance/accounting/journalize.mjs +128 -0
  129. package/dist/finance/accounting/manufacturing.d.mts +8 -0
  130. package/dist/finance/accounting/manufacturing.mjs +236 -0
  131. package/dist/finance/accounting/partnership.d.mts +7 -0
  132. package/dist/finance/accounting/partnership.mjs +152 -0
  133. package/dist/finance/accounting/period-case.d.mts +6 -0
  134. package/dist/finance/accounting/period-case.mjs +71 -0
  135. package/dist/finance/accounting/post.d.mts +9 -0
  136. package/dist/finance/accounting/post.mjs +84 -0
  137. package/dist/finance/accounting/precision.d.mts +9 -0
  138. package/dist/finance/accounting/precision.mjs +15 -0
  139. package/dist/finance/accounting/rules.d.mts +21 -0
  140. package/dist/finance/accounting/rules.mjs +37 -0
  141. package/dist/finance/accounting/solve.d.mts +28 -0
  142. package/dist/finance/accounting/solve.mjs +92 -0
  143. package/dist/finance/accounting/statements.d.mts +7 -0
  144. package/dist/finance/accounting/statements.mjs +142 -0
  145. package/dist/finance/accounting/types.d.mts +649 -0
  146. package/dist/finance/accounting/validate.d.mts +7 -0
  147. package/dist/finance/accounting/validate.mjs +67 -0
  148. package/dist/finance/accounting/verification.d.mts +24 -0
  149. package/dist/finance/accounting/verification.mjs +386 -0
  150. package/dist/finance/bizsim.d.mts +75 -0
  151. package/dist/finance/bizsim.mjs +296 -0
  152. package/dist/finance/index.d.mts +95 -0
  153. package/dist/finance/index.mjs +145 -0
  154. package/dist/finance/investment-math.d.mts +7 -0
  155. package/dist/finance/investment-math.mjs +18 -0
  156. package/dist/finance/management-accounting/budgeting.d.mts +7 -0
  157. package/dist/finance/management-accounting/budgeting.mjs +189 -0
  158. package/dist/finance/management-accounting/cash-budget.d.mts +7 -0
  159. package/dist/finance/management-accounting/cash-budget.mjs +154 -0
  160. package/dist/finance/management-accounting/costing.d.mts +8 -0
  161. package/dist/finance/management-accounting/costing.mjs +175 -0
  162. package/dist/finance/management-accounting/decisions.d.mts +8 -0
  163. package/dist/finance/management-accounting/decisions.mjs +164 -0
  164. package/dist/finance/management-accounting/index.d.mts +13 -0
  165. package/dist/finance/management-accounting/index.mjs +13 -0
  166. package/dist/finance/management-accounting/integrated-budget.d.mts +8 -0
  167. package/dist/finance/management-accounting/integrated-budget.mjs +67 -0
  168. package/dist/finance/management-accounting/inventory-costing.d.mts +7 -0
  169. package/dist/finance/management-accounting/inventory-costing.mjs +173 -0
  170. package/dist/finance/management-accounting/investment-appraisal.d.mts +7 -0
  171. package/dist/finance/management-accounting/investment-appraisal.mjs +148 -0
  172. package/dist/finance/management-accounting/management-case.d.mts +8 -0
  173. package/dist/finance/management-accounting/management-case.mjs +91 -0
  174. package/dist/finance/management-accounting/master-budget.d.mts +7 -0
  175. package/dist/finance/management-accounting/master-budget.mjs +137 -0
  176. package/dist/finance/management-accounting/production-costing.d.mts +8 -0
  177. package/dist/finance/management-accounting/production-costing.mjs +214 -0
  178. package/dist/finance/management-accounting/types.d.mts +644 -0
  179. package/dist/finance/management-accounting/variances.d.mts +7 -0
  180. package/dist/finance/management-accounting/variances.mjs +150 -0
  181. package/dist/index.d.mts +9 -8
  182. package/dist/index.mjs +5 -5
  183. package/dist/interaction/MovableDot.mjs +19 -0
  184. package/dist/interaction/useDraggable.mjs +24 -4
  185. package/dist/math/analysis.d.mts +61 -0
  186. package/dist/math/analysis.mjs +187 -0
  187. package/dist/math/answer-check.d.mts +50 -0
  188. package/dist/math/answer-check.mjs +106 -0
  189. package/dist/math/calculus.d.mts +17 -1
  190. package/dist/math/calculus.mjs +365 -2
  191. package/dist/math/complex.d.mts +93 -0
  192. package/dist/math/complex.mjs +239 -0
  193. package/dist/math/expr.d.mts +23 -0
  194. package/dist/math/expr.mjs +36 -0
  195. package/dist/math/index.d.mts +9 -23
  196. package/dist/math/index.mjs +9 -38
  197. package/dist/math/latex.mjs +10 -1
  198. package/dist/math/parse.mjs +1 -1
  199. package/dist/math/poly.d.mts +55 -0
  200. package/dist/math/poly.mjs +273 -0
  201. package/dist/math/rearrange.d.mts +14 -0
  202. package/dist/math/rearrange.mjs +125 -0
  203. package/dist/math/solve.d.mts +21 -0
  204. package/dist/math/solve.mjs +75 -0
  205. package/dist/networking/addressing.d.mts +26 -0
  206. package/dist/networking/addressing.mjs +33 -0
  207. package/dist/networking/cloud/access.d.mts +36 -0
  208. package/dist/networking/cloud/access.mjs +95 -0
  209. package/dist/networking/cloud/containers.d.mts +43 -0
  210. package/dist/networking/cloud/containers.mjs +54 -0
  211. package/dist/networking/cloud/edge.d.mts +17 -0
  212. package/dist/networking/cloud/edge.mjs +31 -0
  213. package/dist/networking/cloud/failure-domains.d.mts +19 -0
  214. package/dist/networking/cloud/failure-domains.mjs +22 -0
  215. package/dist/networking/cloud/geo-routing.d.mts +22 -0
  216. package/dist/networking/cloud/geo-routing.mjs +64 -0
  217. package/dist/networking/cloud/index.d.mts +18 -0
  218. package/dist/networking/cloud/index.mjs +19 -0
  219. package/dist/networking/cloud/inference-reliability.d.mts +30 -0
  220. package/dist/networking/cloud/inference-reliability.mjs +76 -0
  221. package/dist/networking/cloud/inference.d.mts +118 -0
  222. package/dist/networking/cloud/inference.mjs +179 -0
  223. package/dist/networking/cloud/infrastructure.d.mts +45 -0
  224. package/dist/networking/cloud/infrastructure.mjs +96 -0
  225. package/dist/networking/cloud/observability.d.mts +24 -0
  226. package/dist/networking/cloud/observability.mjs +34 -0
  227. package/dist/networking/cloud/orchestration.d.mts +32 -0
  228. package/dist/networking/cloud/orchestration.mjs +38 -0
  229. package/dist/networking/cloud/recovery.d.mts +21 -0
  230. package/dist/networking/cloud/recovery.mjs +27 -0
  231. package/dist/networking/cloud/releases.d.mts +42 -0
  232. package/dist/networking/cloud/releases.mjs +135 -0
  233. package/dist/networking/cloud/scaling.d.mts +25 -0
  234. package/dist/networking/cloud/scaling.mjs +65 -0
  235. package/dist/networking/cloud/secrets.d.mts +39 -0
  236. package/dist/networking/cloud/secrets.mjs +68 -0
  237. package/dist/networking/cloud/server-deployment.d.mts +29 -0
  238. package/dist/networking/cloud/server-deployment.mjs +72 -0
  239. package/dist/networking/cloud/storage.d.mts +16 -0
  240. package/dist/networking/cloud/storage.mjs +58 -0
  241. package/dist/networking/cloud/vpc.d.mts +18 -0
  242. package/dist/networking/cloud/vpc.mjs +100 -0
  243. package/dist/networking/delivery.d.mts +34 -0
  244. package/dist/networking/delivery.mjs +52 -0
  245. package/dist/networking/index.d.mts +47 -0
  246. package/dist/networking/index.mjs +47 -0
  247. package/dist/networking/ipv6.d.mts +28 -0
  248. package/dist/networking/ipv6.mjs +17 -0
  249. package/dist/networking/journeys.d.mts +83 -0
  250. package/dist/networking/journeys.mjs +161 -0
  251. package/dist/networking/models/airtime.d.mts +87 -0
  252. package/dist/networking/models/airtime.mjs +130 -0
  253. package/dist/networking/models/cellular.d.mts +157 -0
  254. package/dist/networking/models/cellular.mjs +252 -0
  255. package/dist/networking/models/encapsulation.d.mts +98 -0
  256. package/dist/networking/models/encapsulation.mjs +132 -0
  257. package/dist/networking/models/handover.d.mts +116 -0
  258. package/dist/networking/models/handover.mjs +209 -0
  259. package/dist/networking/models/handshake.d.mts +90 -0
  260. package/dist/networking/models/handshake.mjs +122 -0
  261. package/dist/networking/models/index.d.mts +14 -0
  262. package/dist/networking/models/index.mjs +15 -0
  263. package/dist/networking/models/media.d.mts +82 -0
  264. package/dist/networking/models/media.mjs +188 -0
  265. package/dist/networking/models/satellite.d.mts +86 -0
  266. package/dist/networking/models/satellite.mjs +121 -0
  267. package/dist/networking/models/spectrum.d.mts +83 -0
  268. package/dist/networking/models/spectrum.mjs +235 -0
  269. package/dist/networking/models/switch.d.mts +80 -0
  270. package/dist/networking/models/switch.mjs +155 -0
  271. package/dist/networking/models/vlan.d.mts +62 -0
  272. package/dist/networking/models/vlan.mjs +100 -0
  273. package/dist/networking/models/vpn.d.mts +66 -0
  274. package/dist/networking/models/vpn.mjs +125 -0
  275. package/dist/networking/models/wifi-privacy.d.mts +82 -0
  276. package/dist/networking/models/wifi-privacy.mjs +130 -0
  277. package/dist/networking/models/wifi.d.mts +240 -0
  278. package/dist/networking/models/wifi.mjs +562 -0
  279. package/dist/networking/nat-traversal.d.mts +24 -0
  280. package/dist/networking/nat-traversal.mjs +38 -0
  281. package/dist/networking/protocols.d.mts +17 -0
  282. package/dist/networking/protocols.mjs +57 -0
  283. package/dist/networking/queue.d.mts +12 -0
  284. package/dist/networking/queue.mjs +18 -0
  285. package/dist/networking/route-learning.d.mts +23 -0
  286. package/dist/networking/route-learning.mjs +43 -0
  287. package/dist/networking/routing.d.mts +11 -0
  288. package/dist/networking/routing.mjs +25 -0
  289. package/dist/networking/signals.d.mts +26 -0
  290. package/dist/networking/signals.mjs +35 -0
  291. package/dist/networking/subnet.d.mts +49 -0
  292. package/dist/networking/subnet.mjs +89 -0
  293. package/dist/networking/tcp-reliability.d.mts +24 -0
  294. package/dist/networking/tcp-reliability.mjs +38 -0
  295. package/dist/networking/topology/contract.d.mts +123 -0
  296. package/dist/networking/topology/index.d.mts +4 -0
  297. package/dist/networking/topology/index.mjs +4 -0
  298. package/dist/networking/topology/presets.d.mts +7 -0
  299. package/dist/networking/topology/presets.mjs +302 -0
  300. package/dist/networking/topology/simulation.d.mts +8 -0
  301. package/dist/networking/topology/simulation.mjs +179 -0
  302. package/dist/networking/wireless.d.mts +11 -0
  303. package/dist/networking/wireless.mjs +17 -0
  304. package/dist/optics/imaging.d.mts +218 -0
  305. package/dist/optics/imaging.mjs +276 -0
  306. package/dist/optics/index.d.mts +7 -0
  307. package/dist/optics/index.mjs +8 -0
  308. package/dist/optics/laws.d.mts +70 -0
  309. package/dist/optics/laws.mjs +195 -0
  310. package/dist/optics/prism.d.mts +148 -0
  311. package/dist/optics/prism.mjs +197 -0
  312. package/dist/optics/refraction.d.mts +201 -0
  313. package/dist/optics/refraction.mjs +270 -0
  314. package/dist/optics/wave-optics.d.mts +171 -0
  315. package/dist/optics/wave-optics.mjs +259 -0
  316. package/dist/physics/ac/index.d.mts +183 -0
  317. package/dist/physics/ac/index.mjs +203 -0
  318. package/dist/physics/dynamics/forces.d.mts +98 -0
  319. package/dist/physics/dynamics/forces.mjs +153 -0
  320. package/dist/physics/dynamics/friction.d.mts +76 -0
  321. package/dist/physics/dynamics/friction.mjs +119 -0
  322. package/dist/physics/dynamics/system.d.mts +68 -0
  323. package/dist/physics/dynamics/system.mjs +125 -0
  324. package/dist/physics/electrostatics/index.d.mts +169 -0
  325. package/dist/physics/electrostatics/index.mjs +249 -0
  326. package/dist/physics/energy/centre-of-mass.d.mts +115 -0
  327. package/dist/physics/energy/centre-of-mass.mjs +180 -0
  328. package/dist/physics/energy/conservation.d.mts +81 -0
  329. package/dist/physics/energy/conservation.mjs +129 -0
  330. package/dist/physics/energy/power.d.mts +90 -0
  331. package/dist/physics/energy/power.mjs +167 -0
  332. package/dist/physics/energy/spring.d.mts +73 -0
  333. package/dist/physics/energy/spring.mjs +129 -0
  334. package/dist/physics/energy/store.d.mts +63 -0
  335. package/dist/physics/energy/store.mjs +108 -0
  336. package/dist/physics/energy/theorem.d.mts +65 -0
  337. package/dist/physics/energy/theorem.mjs +113 -0
  338. package/dist/physics/energy/work.d.mts +114 -0
  339. package/dist/physics/energy/work.mjs +219 -0
  340. package/dist/physics/gravitation/body.d.mts +85 -0
  341. package/dist/physics/gravitation/body.mjs +168 -0
  342. package/dist/physics/gravitation/kepler.d.mts +127 -0
  343. package/dist/physics/gravitation/kepler.mjs +216 -0
  344. package/dist/physics/gravitation/law.d.mts +117 -0
  345. package/dist/physics/gravitation/law.mjs +175 -0
  346. package/dist/physics/gravitation/orbit.d.mts +119 -0
  347. package/dist/physics/gravitation/orbit.mjs +202 -0
  348. package/dist/physics/gravitation/potential.d.mts +114 -0
  349. package/dist/physics/gravitation/potential.mjs +202 -0
  350. package/dist/physics/gravitation/variation.d.mts +97 -0
  351. package/dist/physics/gravitation/variation.mjs +175 -0
  352. package/dist/physics/index.d.mts +35 -0
  353. package/dist/physics/index.mjs +36 -0
  354. package/dist/physics/integral-sweep.d.mts +63 -0
  355. package/dist/physics/integral-sweep.mjs +126 -0
  356. package/dist/physics/kinematics/equations.d.mts +47 -0
  357. package/dist/physics/kinematics/equations.mjs +126 -0
  358. package/dist/physics/kinematics/free-fall.d.mts +53 -0
  359. package/dist/physics/kinematics/free-fall.mjs +71 -0
  360. package/dist/physics/kinematics/given.d.mts +16 -0
  361. package/dist/physics/kinematics/given.mjs +55 -0
  362. package/dist/physics/kinematics/roots.d.mts +41 -0
  363. package/dist/physics/kinematics/roots.mjs +72 -0
  364. package/dist/physics/kinematics/solve.d.mts +52 -0
  365. package/dist/physics/kinematics/solve.mjs +172 -0
  366. package/dist/physics/magnetism/biot-savart.d.mts +161 -0
  367. package/dist/physics/magnetism/biot-savart.mjs +353 -0
  368. package/dist/physics/magnetism/flux.d.mts +94 -0
  369. package/dist/physics/magnetism/flux.mjs +313 -0
  370. package/dist/physics/magnetism/geomagnetism.d.mts +151 -0
  371. package/dist/physics/magnetism/geomagnetism.mjs +184 -0
  372. package/dist/physics/magnetism/index.d.mts +12 -0
  373. package/dist/physics/magnetism/index.mjs +74 -0
  374. package/dist/physics/magnetism/lorentz.d.mts +28 -0
  375. package/dist/physics/magnetism/lorentz.mjs +88 -0
  376. package/dist/physics/magnetism/magnetic-force.d.mts +102 -0
  377. package/dist/physics/magnetism/magnetic-force.mjs +169 -0
  378. package/dist/physics/momentum/collide.d.mts +77 -0
  379. package/dist/physics/momentum/collide.mjs +115 -0
  380. package/dist/physics/momentum/impulse.d.mts +89 -0
  381. package/dist/physics/momentum/impulse.mjs +159 -0
  382. package/dist/physics/momentum/planar.d.mts +60 -0
  383. package/dist/physics/momentum/planar.mjs +110 -0
  384. package/dist/physics/projectile.d.mts +107 -0
  385. package/dist/physics/projectile.mjs +185 -0
  386. package/dist/physics/rotation/angular.d.mts +85 -0
  387. package/dist/physics/rotation/angular.mjs +130 -0
  388. package/dist/physics/rotation/circular.d.mts +79 -0
  389. package/dist/physics/rotation/circular.mjs +131 -0
  390. package/dist/physics/rotation/inertia.d.mts +164 -0
  391. package/dist/physics/rotation/inertia.mjs +332 -0
  392. package/dist/physics/rotation/torque.d.mts +65 -0
  393. package/dist/physics/rotation/torque.mjs +134 -0
  394. package/dist/physics/vectors.d.mts +64 -0
  395. package/dist/physics/vectors.mjs +114 -0
  396. package/dist/primitives/Dot.d.mts +2 -15
  397. package/dist/primitives/Dot.mjs +6 -4
  398. package/dist/primitives/Grid.d.mts +33 -17
  399. package/dist/primitives/Grid.mjs +89 -17
  400. package/dist/primitives/Label.d.mts +1 -14
  401. package/dist/primitives/Label.mjs +3 -2
  402. package/dist/primitives/Lines.d.mts +4 -32
  403. package/dist/primitives/Lines.mjs +10 -8
  404. package/dist/primitives/Shapes.d.mts +5 -43
  405. package/dist/primitives/Shapes.mjs +12 -10
  406. package/dist/primitives/index.d.mts +2 -2
  407. package/dist/primitives/index.mjs +2 -2
  408. package/dist/primitives/props.mjs +31 -0
  409. package/dist/quantity/index.d.mts +119 -0
  410. package/dist/quantity/index.mjs +417 -0
  411. package/dist/relation/derive.d.mts +74 -0
  412. package/dist/relation/derive.mjs +73 -0
  413. package/dist/relation/index.d.mts +56 -0
  414. package/dist/relation/index.mjs +234 -0
  415. package/dist/scene/Scene.d.mts +6 -1
  416. package/dist/scene/Scene.mjs +15 -40
  417. package/dist/scene/evaluators.mjs +1 -1
  418. package/dist/sim/thermal.mjs +45 -20
  419. package/dist/thermo/calorimetry.d.mts +207 -0
  420. package/dist/thermo/calorimetry.mjs +345 -0
  421. package/dist/thermo/cycles.d.mts +142 -0
  422. package/dist/thermo/cycles.mjs +256 -0
  423. package/dist/thermo/entropy.d.mts +87 -0
  424. package/dist/thermo/entropy.mjs +140 -0
  425. package/dist/thermo/expansion.d.mts +130 -0
  426. package/dist/thermo/expansion.mjs +178 -0
  427. package/dist/thermo/gas.d.mts +197 -0
  428. package/dist/thermo/gas.mjs +279 -0
  429. package/dist/thermo/heat-transfer.d.mts +164 -0
  430. package/dist/thermo/heat-transfer.mjs +217 -0
  431. package/dist/thermo/index.d.mts +9 -82
  432. package/dist/thermo/index.mjs +9 -132
  433. package/dist/thermo/processes.d.mts +95 -0
  434. package/dist/thermo/processes.mjs +154 -0
  435. package/dist/thermo/temperature.d.mts +174 -0
  436. package/dist/thermo/temperature.mjs +236 -0
  437. package/dist/view/Stage.mjs +4 -11
  438. package/dist/waves/damping.d.mts +224 -0
  439. package/dist/waves/damping.mjs +317 -0
  440. package/dist/waves/doppler.d.mts +72 -0
  441. package/dist/waves/doppler.mjs +125 -0
  442. package/dist/waves/index.d.mts +10 -0
  443. package/dist/waves/index.mjs +10 -0
  444. package/dist/waves/pendulum.d.mts +130 -0
  445. package/dist/waves/pendulum.mjs +211 -0
  446. package/dist/waves/pitch.d.mts +125 -0
  447. package/dist/waves/pitch.mjs +158 -0
  448. package/dist/waves/shm.d.mts +170 -0
  449. package/dist/waves/shm.mjs +279 -0
  450. package/dist/waves/springs.d.mts +103 -0
  451. package/dist/waves/springs.mjs +176 -0
  452. package/dist/waves/superposition.d.mts +124 -0
  453. package/dist/waves/superposition.mjs +196 -0
  454. package/dist/waves/wave.d.mts +154 -0
  455. package/dist/waves/wave.mjs +178 -0
  456. package/package.json +103 -23
  457. package/styles.css +125 -8
  458. package/dist/assets/kit/index.mjs +0 -4
@@ -0,0 +1,299 @@
1
+ import { AVOGADRO, GAS_CONSTANT, ZERO_CELSIUS_K } from "../core/constants.mjs";
2
+ import { relation } from "../relation/index.mjs";
3
+
4
+ //#region src/chem/relations.ts
5
+ /**
6
+ * The quantitative relations of chemistry, declared once and solvable in any direction.
7
+ *
8
+ * ## Why declared and not written as functions
9
+ *
10
+ * A textbook ends its quantitative chapter with a page of formulae to memorise, each one written
11
+ * the way it is most often used and rearranged by hand whenever it is not. That page is the part
12
+ * learners photograph and the part they get wrong, because a formula written one way round has to
13
+ * be turned round under exam pressure.
14
+ *
15
+ * A relation has no preferred direction. `n = c * V` answers for the moles, the concentration or
16
+ * the volume, and it shows the rearrangement and the substitution while it does it. So instead of
17
+ * three functions per formula, and a fourth when someone needs the working, there is one
18
+ * declaration:
19
+ *
20
+ * ```ts
21
+ * MOLES_FROM_SOLUTION.solve({ c: 0.100, V: qty(24.50, 'cm3') }); // n, straight off the burette
22
+ * MOLES_FROM_SOLUTION.solve({ n: 2.45e-3, V: 0.0245 }); // c, the titration answer
23
+ * MOLES_FROM_SOLUTION.steps({ c: 0.100, V: 0.0245 }); // the working, line by line
24
+ * ```
25
+ *
26
+ * ## Units are checked when the relation is declared
27
+ *
28
+ * A relation whose units do not balance is refused at declaration, before anything can be written
29
+ * against it. That matters more than it sounds: a wrong formula that lessons, labs and the marker
30
+ * all share is worse than no formula, because everything then agrees and everything is wrong.
31
+ *
32
+ * It also means a volume can be given in cubic centimetres against a concentration in mol per cubic
33
+ * decimetre, and the factor of a thousand sorts itself out. That single conversion is the most
34
+ * common arithmetic slip in volumetric analysis, and here it is not a step anyone performs.
35
+ *
36
+ * ## Declared lazily, so importing one does not build them all
37
+ *
38
+ * Each is behind a getter that builds it on first use and remembers it. Building nineteen relations
39
+ * at import time would parse nineteen expressions and run nineteen dimensional checks for a caller
40
+ * that wanted one, and would pin all of them into any bundle that touched this file.
41
+ *
42
+ * Pure: no React, no pixels.
43
+ */
44
+ /** Build once, on first use. */
45
+ function lazy(build) {
46
+ let made;
47
+ return () => made ??= build();
48
+ }
49
+ /** `n = m / M`, moles from a mass weighed out. */
50
+ const molesFromMass = lazy(() => relation("n = m / M", {
51
+ n: "mol",
52
+ m: "g",
53
+ M: "g/mol"
54
+ }, "moles from mass"));
55
+ /** `n = c * V`, moles in a volume of solution. Give V in cm3 and the conversion looks after itself. */
56
+ const molesFromSolution = lazy(() => relation("n = c * V", {
57
+ n: "mol",
58
+ c: "mol/dm3",
59
+ V: "dm3"
60
+ }, "moles in a solution"));
61
+ /** `n = N / L`, moles from a number of particles. */
62
+ const molesFromParticles = lazy(() => relation("n = N / L", {
63
+ n: "mol",
64
+ N: "1",
65
+ L: "1/mol"
66
+ }, "moles from a particle count"));
67
+ /**
68
+ * `n = V / Vm`, moles of a gas from its volume at a stated molar volume.
69
+ *
70
+ * The molar volume is a variable rather than a constant baked in, because it is not one: it depends
71
+ * on temperature and pressure, and quoting 22.4 dm3/mol without saying "at standard temperature and
72
+ * pressure" is where a great many wrong answers begin.
73
+ */
74
+ const molesFromGasVolume = lazy(() => relation("n = V / Vm", {
75
+ n: "mol",
76
+ V: "dm3",
77
+ Vm: "dm3/mol"
78
+ }, "moles of a gas"));
79
+ /** `P * V = n * R * T`, the ideal gas equation. Temperature in kelvin, as it must be. */
80
+ const idealGas = lazy(() => relation("P * V = n * R * T", {
81
+ P: "Pa",
82
+ V: "m3",
83
+ n: "mol",
84
+ R: "J/mol/K",
85
+ T: "K"
86
+ }, "the ideal gas equation"));
87
+ /** `P1 * V1 / T1 = P2 * V2 / T2`, one gas under two sets of conditions. */
88
+ const combinedGasLaw = lazy(() => relation("P1 * V1 / T1 = P2 * V2 / T2", {
89
+ P1: "Pa",
90
+ V1: "m3",
91
+ T1: "K",
92
+ P2: "Pa",
93
+ V2: "m3",
94
+ T2: "K"
95
+ }, "the combined gas law"));
96
+ /** `c = n / V`, concentration from moles and volume. */
97
+ const concentration = lazy(() => relation("c = n / V", {
98
+ c: "mol/dm3",
99
+ n: "mol",
100
+ V: "dm3"
101
+ }, "concentration"));
102
+ /**
103
+ * `c1 * V1 = c2 * V2`, dilution.
104
+ *
105
+ * True because the moles do not change when water is added, which is the whole of the derivation
106
+ * and is worth saying every time it is used.
107
+ */
108
+ const dilution = lazy(() => relation("c1 * V1 = c2 * V2", {
109
+ c1: "mol/dm3",
110
+ V1: "dm3",
111
+ c2: "mol/dm3",
112
+ V2: "dm3"
113
+ }, "dilution"));
114
+ /** `m_conc = c * V * M`, the mass to weigh out to make up a standard solution. */
115
+ const massForSolution = lazy(() => relation("m = c * V * M", {
116
+ m: "g",
117
+ c: "mol/dm3",
118
+ V: "dm3",
119
+ M: "g/mol"
120
+ }, "mass for a standard solution"));
121
+ /**
122
+ * `b = n / m_solvent`, molality: moles of solute per kilogram of SOLVENT.
123
+ *
124
+ * Not per kilogram of solution, and not per litre of anything. The distinction from molarity is the
125
+ * point of having both: molality uses a mass, so it does not change when the temperature does,
126
+ * which is why it is the one that appears in freezing point and boiling point work.
127
+ */
128
+ const molality = lazy(() => relation("b = n / ms", {
129
+ b: "mol/kg",
130
+ n: "mol",
131
+ ms: "kg"
132
+ }, "molality"));
133
+ /** `rho = m / V`, density, which is what converts between a volume and a mass of solution. */
134
+ const density = lazy(() => relation("rho = m / V", {
135
+ rho: "g/cm3",
136
+ m: "g",
137
+ V: "cm3"
138
+ }, "density"));
139
+ /**
140
+ * `A = eps * c * l`, the Beer-Lambert law.
141
+ *
142
+ * Absorbance is dimensionless: it is a logarithm of a ratio of intensities, so it has no unit, and
143
+ * the molar absorptivity carries whatever is needed to cancel the concentration and the path
144
+ * length. Declaring it that way is what lets the units check pass, and it is also the honest
145
+ * description of what absorbance is.
146
+ *
147
+ * Solving it for the concentration is the entire quantitative use of a colorimeter: measure the
148
+ * absorbance of a coloured solution, and read its concentration off.
149
+ */
150
+ const beerLambert = lazy(() => relation("A = eps * c * l", {
151
+ A: "1",
152
+ eps: "dm3/mol/cm",
153
+ c: "mol/dm3",
154
+ l: "cm"
155
+ }, "the Beer-Lambert law"));
156
+ /**
157
+ * `A = log10(I0 / I)`, absorbance from the light that went in and the light that came out.
158
+ *
159
+ * The definition the law above is built on, and the reason absorbance has no unit.
160
+ */
161
+ const absorbanceFromIntensity = lazy(() => relation("A = log10(I0 / I)", {
162
+ A: "1",
163
+ I0: "1",
164
+ I: "1"
165
+ }, "absorbance from transmitted light"));
166
+ /** `q = m * c * dT`, the heat a measured temperature change accounts for. */
167
+ const heatEnergy = lazy(() => relation("q = m * cs * dT", {
168
+ q: "J",
169
+ m: "g",
170
+ cs: "J/g/K",
171
+ dT: "K"
172
+ }, "heat from a temperature change"));
173
+ /**
174
+ * The values these relations are usually fed, kept as data with their units attached.
175
+ *
176
+ * Passed in rather than compiled into the relations. A molar volume of 24 dm3/mol is only right at
177
+ * room temperature and 22.4 only at standard temperature and pressure, and a relation that hid
178
+ * either inside itself would give a confidently wrong answer under the other conditions.
179
+ */
180
+ const CONSTANTS = {
181
+ /** Avogadro constant, per mole. */
182
+ avogadro: AVOGADRO,
183
+ /** Molar gas constant, J per mole per kelvin. */
184
+ gasConstant: GAS_CONSTANT,
185
+ /** Molar volume of an ideal gas at 273.15 K and 100 kPa, dm3 per mole. */
186
+ molarVolumeStp: 22.7,
187
+ /** Molar volume at 298 K and 100 kPa, dm3 per mole: the figure room-temperature questions use. */
188
+ molarVolumeRoom: 24,
189
+ /** Specific heat capacity of water, J per gram per kelvin. */
190
+ waterHeatCapacity: 4.18
191
+ };
192
+ /** Kelvin from degrees Celsius. One line, and the source of a great many wrong gas answers. */
193
+ const kelvinFrom = (celsius) => celsius + ZERO_CELSIUS_K;
194
+ /**
195
+ * The derivations, so a lesson can say why a formula is true and not only how to use it.
196
+ *
197
+ * Three kinds, and the difference between them is worth as much as the formulae. A definition has
198
+ * nothing underneath it. A derived relation follows from others plus something held fixed, and the
199
+ * chain is executable, so the claim is checked rather than asserted. A measured one was observed by
200
+ * somebody, and saying so is the difference between teaching chemistry and teaching a formula
201
+ * sheet.
202
+ */
203
+ const DERIVATIONS = {
204
+ /**
205
+ * Dilution, the one everyone memorises and nobody can justify.
206
+ *
207
+ * The argument is three sentences long. Adding water changes the volume and changes the
208
+ * concentration, and does not change the number of moles. So `n = cV` holds at both ends with the
209
+ * same n, and that is the rule.
210
+ */
211
+ dilution: {
212
+ kind: "derived",
213
+ summary: "Adding water changes how much there is of the solution and how concentrated it is, and changes nothing about how much solute is in it.",
214
+ invariant: "the number of moles of solute, which water does not create or destroy",
215
+ arrivesAt: "c2",
216
+ steps: [{
217
+ relation: molesFromSolution,
218
+ solveFor: "n",
219
+ using: {
220
+ c: "c1",
221
+ V: "V1"
222
+ },
223
+ gives: "n",
224
+ because: "first find how many moles the stock solution you measured out actually contains"
225
+ }, {
226
+ relation: concentration,
227
+ solveFor: "c",
228
+ using: {
229
+ n: "n",
230
+ V: "V2"
231
+ },
232
+ gives: "c2",
233
+ because: "those same moles are now spread through the larger volume, so the concentration is what they make up in it"
234
+ }]
235
+ },
236
+ /**
237
+ * The mass to weigh out for a standard solution.
238
+ *
239
+ * Two definitions laid end to end, which is worth showing because learners meet it as a third
240
+ * formula rather than as the two they already have.
241
+ */
242
+ massForSolution: {
243
+ kind: "derived",
244
+ summary: "You cannot weigh out moles, so work out how many moles the solution needs and then what that many moles weigh.",
245
+ invariant: "nothing is held fixed here: this is two definitions used one after the other",
246
+ arrivesAt: "m",
247
+ steps: [{
248
+ relation: molesFromSolution,
249
+ solveFor: "n",
250
+ using: {
251
+ c: "c",
252
+ V: "V"
253
+ },
254
+ gives: "n",
255
+ because: "the volume you are making up, at the concentration you want, needs this many moles"
256
+ }, {
257
+ relation: molesFromMass,
258
+ solveFor: "m",
259
+ using: {
260
+ n: "n",
261
+ M: "M"
262
+ },
263
+ gives: "m",
264
+ because: "and that many moles of this substance weigh this much, which is what goes on the balance"
265
+ }]
266
+ },
267
+ concentration: {
268
+ kind: "definition",
269
+ summary: "Concentration is how many moles are dissolved in each unit of volume. That is what the word means."
270
+ },
271
+ molesFromMass: {
272
+ kind: "definition",
273
+ summary: "Molar mass is defined as the mass of one mole, so dividing a mass by it counts how many moles that mass is."
274
+ },
275
+ /**
276
+ * The Beer-Lambert law, which is measured and is usually taught as though it were not.
277
+ *
278
+ * It is stated as a formula with no hint that anyone ever checked it, and it does in fact fail:
279
+ * at high concentrations absorbance stops rising in step, which is why a calibration curve is
280
+ * drawn and a sample too dark to read is diluted before it is measured.
281
+ */
282
+ beerLambert: {
283
+ kind: "measured",
284
+ summary: "Each layer of a solution takes the same FRACTION of the light reaching it, so the light left falls away multiplicatively and its logarithm falls in step with both the concentration and the distance travelled.",
285
+ evidence: "Measured: double the concentration of a coloured solution, or double the length of the cell, and the absorbance doubles. It stops holding at high concentrations, which is why a calibration curve is plotted rather than assumed and why a dark sample is diluted before it is read."
286
+ },
287
+ idealGas: {
288
+ kind: "measured",
289
+ summary: "Pressure times volume divided by temperature comes to the same thing for any gas, once there is enough of it to average over and the particles are far enough apart to ignore each other.",
290
+ evidence: "Measured, and by three separate people on three separate pairs of variables before anyone combined them. It is a limit rather than a law: every real gas departs from it as it is compressed or cooled toward its boiling point, which is exactly when its particles stop being far apart."
291
+ },
292
+ heatEnergy: {
293
+ kind: "definition",
294
+ summary: "Specific heat capacity is defined as the energy one gram needs to warm by one kelvin, so the total is that energy times the grams times the kelvin."
295
+ }
296
+ };
297
+
298
+ //#endregion
299
+ export { CONSTANTS, DERIVATIONS, absorbanceFromIntensity, beerLambert, combinedGasLaw, concentration, density, dilution, heatEnergy, idealGas, kelvinFrom, massForSolution, molality, molesFromGasVolume, molesFromMass, molesFromParticles, molesFromSolution };
@@ -0,0 +1,51 @@
1
+ import { Structure } from "./molecule.mjs";
2
+
3
+ //#region src/chem/skeleton.d.ts
4
+ /**
5
+ * Atoms that lie on a ring, as one list per ring.
6
+ *
7
+ * Found by removing terminal atoms repeatedly: whatever survives is the ring system, because only a
8
+ * ring has no free end to peel. Simple, and right for the one-ring molecules this subset covers.
9
+ */
10
+ declare function ringSystems(structure: Structure): number[][];
11
+ /**
12
+ * The longest chain through the structure, as atom ids in order.
13
+ *
14
+ * ## Which atoms count as backbone
15
+ *
16
+ * Every carbon, plus any heteroatom the chain RUNS THROUGH. The ester oxygen and the amide nitrogen
17
+ * are in the middle of a chain and are drawn in it; a carbonyl oxygen, a hydroxyl, an amine or a
18
+ * halogen hangs off the side and is drawn as a substituent.
19
+ *
20
+ * The test is how many bonds the atom has out into the skeleton, counting an open valence as one,
21
+ * because an open valence is where the chain continues into the next repeat unit. Two or more means
22
+ * the chain passes through.
23
+ *
24
+ * Restricting the walk to CARBON was the first version and it broke the thing this exists for: a
25
+ * nylon repeat unit is a chain of six carbons, an amide nitrogen and six more carbons, and a walk
26
+ * that could not cross the nitrogen reported half the molecule as one enormous substituent, which
27
+ * the drawing then collapsed into the label "C6H29N2".
28
+ *
29
+ * Ring atoms are excluded, because a ring is reported separately by {@link backboneOf}.
30
+ */
31
+ declare function longestChain(structure: Structure): number[];
32
+ interface Backbone {
33
+ /** The atoms drawn across the page, in order. */
34
+ readonly atoms: readonly number[];
35
+ /** The backbone is a closed ring rather than an open chain. */
36
+ readonly ring: boolean;
37
+ /** True when the ring is aromatic, so it takes a circle rather than alternating bonds. */
38
+ readonly aromatic: boolean;
39
+ /** Everything else, grouped by which backbone atom it hangs from. */
40
+ readonly branches: ReadonlyMap<number, readonly number[]>;
41
+ }
42
+ /**
43
+ * The backbone and its branches.
44
+ *
45
+ * A branch is every atom reachable from a backbone atom without going back through the backbone, so
46
+ * a carboxyl group on a ring comes back as three atoms attached at one vertex rather than as three
47
+ * unrelated neighbours.
48
+ */
49
+ declare function backboneOf(structure: Structure): Backbone;
50
+ //#endregion
51
+ export { Backbone, backboneOf, longestChain, ringSystems };
@@ -0,0 +1,186 @@
1
+ import { bondsAt, otherEnd } from "./molecule.mjs";
2
+
3
+ //#region src/chem/skeleton.ts
4
+ /**
5
+ * skeleton, the backbone of a structure and what hangs off it.
6
+ *
7
+ * WHAT THIS IS FOR. Two jobs need the same answer. Drawing a molecule needs to know which atoms form
8
+ * the chain that runs across the page and which are substituents hanging off it. Naming a molecule
9
+ * needs exactly the same thing, because an IUPAC name is the longest chain plus its branches. So the
10
+ * perception is done once, here, and returns atom ids rather than coordinates or syllables.
11
+ *
12
+ * ## Why the longest chain, and what "longest" means
13
+ *
14
+ * The backbone is the longest path through the skeleton, which is every carbon plus the heteroatoms
15
+ * the chain runs THROUGH: the oxygen in an ester link, the nitrogen in an amide. A carbonyl oxygen
16
+ * or a hydroxyl hangs off the side and is a substituent. Found by the standard trick for a tree:
17
+ * walk from any atom to the furthest one, then walk again from there, and the second walk traces the
18
+ * diameter.
19
+ *
20
+ * ## Rings come first
21
+ *
22
+ * A ring is not a chain and cannot be drawn as one, so a structure containing a ring reports the
23
+ * ring as its backbone and everything else as substituents. That is also how a chemist draws it:
24
+ * benzene-1,4-dicarboxylic acid is a hexagon with two groups on it, not a chain with a hexagon in
25
+ * the middle.
26
+ *
27
+ * ## The subset this handles, stated rather than implied
28
+ *
29
+ * One ring, and substituents that are single atoms or small terminal groups. That covers every
30
+ * molecule in AS and A2 organic chemistry. A fused polycyclic, or a long branch off a long branch,
31
+ * returns a backbone that is correct and a drawing that would be cramped, and the honest answer
32
+ * there is a hand-placed structure rather than a computed one.
33
+ *
34
+ * Pure: no React, no pixels.
35
+ */
36
+ /** Heavy atoms bonded to this one. */
37
+ const linked = (structure, id) => bondsAt(structure, id).map((b) => otherEnd(b, id));
38
+ /**
39
+ * Atoms that lie on a ring, as one list per ring.
40
+ *
41
+ * Found by removing terminal atoms repeatedly: whatever survives is the ring system, because only a
42
+ * ring has no free end to peel. Simple, and right for the one-ring molecules this subset covers.
43
+ */
44
+ function ringSystems(structure) {
45
+ const alive = new Set(structure.atoms.map((a) => a.id));
46
+ let peeled = true;
47
+ while (peeled) {
48
+ peeled = false;
49
+ for (const id of [...alive]) if (linked(structure, id).filter((n) => alive.has(n)).length <= 1) {
50
+ alive.delete(id);
51
+ peeled = true;
52
+ }
53
+ }
54
+ if (alive.size === 0) return [];
55
+ const systems = [];
56
+ const seen = /* @__PURE__ */ new Set();
57
+ for (const id of alive) {
58
+ if (seen.has(id)) continue;
59
+ const piece = [];
60
+ const stack = [id];
61
+ seen.add(id);
62
+ while (stack.length) {
63
+ const at = stack.pop();
64
+ piece.push(at);
65
+ for (const n of linked(structure, at)) if (alive.has(n) && !seen.has(n)) {
66
+ seen.add(n);
67
+ stack.push(n);
68
+ }
69
+ }
70
+ systems.push(piece);
71
+ }
72
+ return systems;
73
+ }
74
+ /** Walk outward from an atom, returning the furthest one and the path to it. */
75
+ function furthest(structure, from, only) {
76
+ const previous = /* @__PURE__ */ new Map();
77
+ const seen = new Set([from]);
78
+ let frontier = [from];
79
+ let last = from;
80
+ while (frontier.length) {
81
+ const next = [];
82
+ for (const at of frontier) {
83
+ last = at;
84
+ for (const n of linked(structure, at)) {
85
+ if (!only.has(n) || seen.has(n)) continue;
86
+ seen.add(n);
87
+ previous.set(n, at);
88
+ next.push(n);
89
+ }
90
+ }
91
+ if (next.length) frontier = next;
92
+ else break;
93
+ }
94
+ const path = [last];
95
+ let cursor = last;
96
+ while (previous.has(cursor)) {
97
+ cursor = previous.get(cursor);
98
+ path.unshift(cursor);
99
+ }
100
+ return path;
101
+ }
102
+ /**
103
+ * The longest chain through the structure, as atom ids in order.
104
+ *
105
+ * ## Which atoms count as backbone
106
+ *
107
+ * Every carbon, plus any heteroatom the chain RUNS THROUGH. The ester oxygen and the amide nitrogen
108
+ * are in the middle of a chain and are drawn in it; a carbonyl oxygen, a hydroxyl, an amine or a
109
+ * halogen hangs off the side and is drawn as a substituent.
110
+ *
111
+ * The test is how many bonds the atom has out into the skeleton, counting an open valence as one,
112
+ * because an open valence is where the chain continues into the next repeat unit. Two or more means
113
+ * the chain passes through.
114
+ *
115
+ * Restricting the walk to CARBON was the first version and it broke the thing this exists for: a
116
+ * nylon repeat unit is a chain of six carbons, an amide nitrogen and six more carbons, and a walk
117
+ * that could not cross the nitrogen reported half the molecule as one enormous substituent, which
118
+ * the drawing then collapsed into the label "C6H29N2".
119
+ *
120
+ * Ring atoms are excluded, because a ring is reported separately by {@link backboneOf}.
121
+ */
122
+ function longestChain(structure) {
123
+ const inRing = new Set(ringSystems(structure).flat());
124
+ const eligible = new Set(structure.atoms.filter((a) => {
125
+ if (inRing.has(a.id)) return false;
126
+ if (a.element === "C") return true;
127
+ return linked(structure, a.id).length + (a.openValence ?? 0) >= 2;
128
+ }).map((a) => a.id));
129
+ if (eligible.size === 0) return [];
130
+ const start = [...eligible][0];
131
+ const firstPath = furthest(structure, start, eligible);
132
+ const end = firstPath[firstPath.length - 1];
133
+ return furthest(structure, end, eligible);
134
+ }
135
+ /**
136
+ * The backbone and its branches.
137
+ *
138
+ * A branch is every atom reachable from a backbone atom without going back through the backbone, so
139
+ * a carboxyl group on a ring comes back as three atoms attached at one vertex rather than as three
140
+ * unrelated neighbours.
141
+ */
142
+ function backboneOf(structure) {
143
+ const ring = ringSystems(structure)[0];
144
+ const atoms = ring && ring.length >= 3 ? orderRing(structure, ring) : longestChain(structure);
145
+ const onBackbone = new Set(atoms);
146
+ const branches = /* @__PURE__ */ new Map();
147
+ for (const id of atoms) for (const start of linked(structure, id)) {
148
+ if (onBackbone.has(start)) continue;
149
+ const group = [];
150
+ const seen = new Set([start, ...onBackbone]);
151
+ const stack = [start];
152
+ while (stack.length) {
153
+ const at = stack.pop();
154
+ group.push(at);
155
+ for (const n of linked(structure, at)) {
156
+ if (seen.has(n)) continue;
157
+ seen.add(n);
158
+ stack.push(n);
159
+ }
160
+ }
161
+ branches.set(id, [...branches.get(id) ?? [], ...group]);
162
+ }
163
+ return {
164
+ atoms,
165
+ ring: Boolean(ring && ring.length >= 3),
166
+ aromatic: Boolean(ring?.every((id) => structure.atoms[id].aromatic)),
167
+ branches
168
+ };
169
+ }
170
+ /** Put a ring's atoms in the order they are bonded, so a polygon can be walked round. */
171
+ function orderRing(structure, ring) {
172
+ const inRing = new Set(ring);
173
+ const ordered = [ring[0]];
174
+ const seen = new Set(ordered);
175
+ while (ordered.length < ring.length) {
176
+ const at = ordered[ordered.length - 1];
177
+ const next = linked(structure, at).find((n) => inRing.has(n) && !seen.has(n));
178
+ if (next === void 0) break;
179
+ seen.add(next);
180
+ ordered.push(next);
181
+ }
182
+ return ordered;
183
+ }
184
+
185
+ //#endregion
186
+ export { backboneOf, longestChain, ringSystems };
@@ -0,0 +1,116 @@
1
+ //#region src/chem/solution.d.ts
2
+ /**
3
+ * Sparingly soluble salts: how much dissolves, and when something comes out of solution.
4
+ *
5
+ * ## Why a solubility product exists at all
6
+ *
7
+ * A salt that barely dissolves sits in equilibrium with its own ions. Once the solid is there, more
8
+ * solid changes nothing about the solution, so the equilibrium constant contains only the ions:
9
+ *
10
+ * MpAq(s) ⇌ p M^q+(aq) + q A^p-(aq) Ksp = [M]^p [A]^q
11
+ *
12
+ * That is the whole definition, and everything else here follows from it plus counting.
13
+ *
14
+ * ## Why Ksp values cannot be compared directly, which is the standard trap
15
+ *
16
+ * Silver chloride has a Ksp of 1.8e-10 and silver chromate 1.1e-12, so the chromate looks a hundred
17
+ * times less soluble. It is roughly seven times MORE soluble. The numbers are not comparable
18
+ * because they are not the same kind of number: one is a product of two concentrations and the
19
+ * other of three, so they have different units and different powers.
20
+ *
21
+ * The only honest comparison is between SOLUBILITIES, which is what {@link solubilityFromKsp}
22
+ * computes, and it is computed rather than tabulated so the comparison can be made for any pair.
23
+ *
24
+ * ## Precipitation is a comparison, not a rule
25
+ *
26
+ * Mixing two solutions does not ask whether a salt is "insoluble". It asks whether the ions that
27
+ * are now present exceed what the solution can hold: form the same product from the ACTUAL
28
+ * concentrations and compare it with Ksp. Above it, solid appears until the product falls back;
29
+ * below it, nothing happens however insoluble the salt is said to be.
30
+ *
31
+ * Pure: no React, no pixels.
32
+ */
33
+ /** A salt as its stoichiometry: p cations of charge q+, q anions of charge p-. */
34
+ interface SaltFormula {
35
+ readonly formula: string;
36
+ /** Cations per formula unit. */
37
+ readonly cations: number;
38
+ /** Anions per formula unit. */
39
+ readonly anions: number;
40
+ }
41
+ interface SparinglySoluble extends SaltFormula {
42
+ /** Solubility product at 298 K. Units depend on the stoichiometry, which is the point. */
43
+ readonly ksp: number;
44
+ }
45
+ /**
46
+ * Solubility products at 298 K, from standard tables.
47
+ *
48
+ * Deliberately a mixed set of stoichiometries. A table of nothing but 1:1 salts would let the
49
+ * comparison trap below stay invisible, which is the one thing this data is most useful for.
50
+ */
51
+ declare const SOLUBILITY_PRODUCTS: readonly SparinglySoluble[];
52
+ declare const saltByFormula: (formula: string) => SparinglySoluble | undefined;
53
+ /**
54
+ * The solubility product a given solubility implies.
55
+ *
56
+ * Dissolving S moles of MpAq gives pS of the cation and qS of the anion, so the product is
57
+ * (pS)^p (qS)^q. The powers and the multipliers are both there, and dropping either is the usual
58
+ * way this goes wrong: silver chromate gives (2S)²(S), not S³ and not (2S)(S).
59
+ */
60
+ declare function kspFromSolubility(salt: SaltFormula, solubility: number): number;
61
+ /**
62
+ * The solubility a solubility product implies, in mol per cubic decimetre.
63
+ *
64
+ * The inverse of the above, solved rather than rearranged by hand, because the rearrangement is a
65
+ * different expression for every stoichiometry:
66
+ *
67
+ * Ksp = p^p q^q S^(p+q) so S = (Ksp / (p^p q^q))^(1/(p+q))
68
+ */
69
+ declare function solubilityFromKsp(salt: SparinglySoluble): number;
70
+ /**
71
+ * The ionic product for concentrations that are actually present.
72
+ *
73
+ * The same expression as Ksp and a different quantity: Ksp is what a SATURATED solution has, this
74
+ * is what THIS solution has. Comparing them is the whole of precipitation prediction, and calling
75
+ * both of them Ksp is why that comparison so often gets skipped.
76
+ */
77
+ declare function ionicProduct(salt: SaltFormula, cation: number, anion: number): number;
78
+ type PrecipitationVerdict = 'precipitate' | 'saturated' | 'stays dissolved';
79
+ interface PrecipitationCheck {
80
+ readonly ionicProduct: number;
81
+ readonly ksp: number;
82
+ readonly verdict: PrecipitationVerdict;
83
+ readonly because: string;
84
+ }
85
+ /**
86
+ * Whether mixing these concentrations produces a solid.
87
+ *
88
+ * Returns the reasoning, because "will it precipitate" is answered by a comparison and a learner
89
+ * who is handed only the verdict never sees which two numbers were compared.
90
+ */
91
+ declare function willPrecipitate(salt: SparinglySoluble, cation: number, anion: number): PrecipitationCheck;
92
+ /**
93
+ * Solubility when one of the ions is already in the water: the common ion effect.
94
+ *
95
+ * Adding chloride to a saturated silver chloride solution pushes the equilibrium back and less
96
+ * silver chloride dissolves. The equilibrium itself has not changed; there is simply less room.
97
+ *
98
+ * Solved numerically rather than algebraically. With a common ion the equation is
99
+ * (pS + existing)^p (qS)^q = Ksp for a common cation, which is a polynomial of degree p+q with no
100
+ * tidy closed form beyond the simplest salts. It is monotonic in S, so bisection finds the root
101
+ * exactly and works for every stoichiometry rather than for the two that factorise.
102
+ */
103
+ declare function solubilityWithCommonIon(salt: SparinglySoluble, existing: number, ion?: 'cation' | 'anion'): number;
104
+ /**
105
+ * Compare two salts by how much of each actually dissolves.
106
+ *
107
+ * The reason this exists rather than a sort on Ksp: silver chloride's 1.8e-10 against silver
108
+ * chromate's 1.1e-12 says the chromate is a hundred times less soluble, and it is about seven times
109
+ * MORE soluble. The two numbers are products of different numbers of concentrations, so they are
110
+ * not the same kind of quantity and comparing them is meaningless.
111
+ */
112
+ declare function moreSoluble(a: SparinglySoluble, b: SparinglySoluble): SparinglySoluble;
113
+ /** Whether comparing two salts by Ksp alone would give the wrong answer. */
114
+ declare const kspComparisonMisleads: (a: SparinglySoluble, b: SparinglySoluble) => boolean;
115
+ //#endregion
116
+ export { PrecipitationCheck, PrecipitationVerdict, SOLUBILITY_PRODUCTS, SaltFormula, SparinglySoluble, ionicProduct, kspComparisonMisleads, kspFromSolubility, moreSoluble, saltByFormula, solubilityFromKsp, solubilityWithCommonIon, willPrecipitate };