@motionscript/math 0.0.0-stage → 0.1.0-alpha.10

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 (335) hide show
  1. package/CHANGELOG.md +144 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +49 -0
  4. package/README.md +389 -2
  5. package/dist/annotate/angle-mark.d.ts +96 -0
  6. package/dist/annotate/angle-mark.d.ts.map +1 -0
  7. package/dist/annotate/angle-mark.js +97 -0
  8. package/dist/annotate/angle-mark.js.map +1 -0
  9. package/dist/annotate/curly-brace.d.ts +115 -0
  10. package/dist/annotate/curly-brace.d.ts.map +1 -0
  11. package/dist/annotate/curly-brace.js +99 -0
  12. package/dist/annotate/curly-brace.js.map +1 -0
  13. package/dist/annotate/emphasis-mark.d.ts +80 -0
  14. package/dist/annotate/emphasis-mark.d.ts.map +1 -0
  15. package/dist/annotate/emphasis-mark.js +80 -0
  16. package/dist/annotate/emphasis-mark.js.map +1 -0
  17. package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
  18. package/dist/browser/chunks/chunk-IRZCG6PM.js +2 -0
  19. package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
  20. package/dist/browser/chunks/chunk-WMVW6ZIV.js +2 -0
  21. package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
  22. package/dist/browser/chunks/mathjax-WV55AC2P.js +61 -0
  23. package/dist/browser/chunks/mathjax-WV55AC2P.js.map +7 -0
  24. package/dist/browser/index.js +2 -0
  25. package/dist/browser/index.js.map +7 -0
  26. package/dist/browser/kit.js +2 -0
  27. package/dist/browser/kit.js.map +7 -0
  28. package/dist/browser/manifest.json +30 -0
  29. package/dist/browser/tex.js +2 -0
  30. package/dist/browser/tex.js.map +7 -0
  31. package/dist/engine.d.ts +71 -0
  32. package/dist/engine.d.ts.map +1 -0
  33. package/dist/engine.js +45 -0
  34. package/dist/engine.js.map +1 -0
  35. package/dist/index.d.ts +30 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +30 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/kit/brace.d.ts +8 -0
  40. package/dist/kit/brace.d.ts.map +1 -0
  41. package/dist/kit/brace.js +36 -0
  42. package/dist/kit/brace.js.map +1 -0
  43. package/dist/kit/cache.d.ts +30 -0
  44. package/dist/kit/cache.d.ts.map +1 -0
  45. package/dist/kit/cache.js +53 -0
  46. package/dist/kit/cache.js.map +1 -0
  47. package/dist/kit/component.d.ts +51 -0
  48. package/dist/kit/component.d.ts.map +1 -0
  49. package/dist/kit/component.js +30 -0
  50. package/dist/kit/component.js.map +1 -0
  51. package/dist/kit/contour.d.ts +8 -0
  52. package/dist/kit/contour.d.ts.map +1 -0
  53. package/dist/kit/contour.js +93 -0
  54. package/dist/kit/contour.js.map +1 -0
  55. package/dist/kit/coords.d.ts +69 -0
  56. package/dist/kit/coords.d.ts.map +1 -0
  57. package/dist/kit/coords.js +224 -0
  58. package/dist/kit/coords.js.map +1 -0
  59. package/dist/kit/curve.d.ts +28 -0
  60. package/dist/kit/curve.d.ts.map +1 -0
  61. package/dist/kit/curve.js +29 -0
  62. package/dist/kit/curve.js.map +1 -0
  63. package/dist/kit/equation.d.ts +61 -0
  64. package/dist/kit/equation.d.ts.map +1 -0
  65. package/dist/kit/equation.js +168 -0
  66. package/dist/kit/equation.js.map +1 -0
  67. package/dist/kit/equation3d.d.ts +50 -0
  68. package/dist/kit/equation3d.d.ts.map +1 -0
  69. package/dist/kit/equation3d.js +103 -0
  70. package/dist/kit/equation3d.js.map +1 -0
  71. package/dist/kit/expression.d.ts +35 -0
  72. package/dist/kit/expression.d.ts.map +1 -0
  73. package/dist/kit/expression.js +124 -0
  74. package/dist/kit/expression.js.map +1 -0
  75. package/dist/kit/field-mark.d.ts +79 -0
  76. package/dist/kit/field-mark.d.ts.map +1 -0
  77. package/dist/kit/field-mark.js +109 -0
  78. package/dist/kit/field-mark.js.map +1 -0
  79. package/dist/kit/field.d.ts +14 -0
  80. package/dist/kit/field.d.ts.map +1 -0
  81. package/dist/kit/field.js +46 -0
  82. package/dist/kit/field.js.map +1 -0
  83. package/dist/kit/follow.d.ts +109 -0
  84. package/dist/kit/follow.d.ts.map +1 -0
  85. package/dist/kit/follow.js +163 -0
  86. package/dist/kit/follow.js.map +1 -0
  87. package/dist/kit/furniture.d.ts +32 -0
  88. package/dist/kit/furniture.d.ts.map +1 -0
  89. package/dist/kit/furniture.js +92 -0
  90. package/dist/kit/furniture.js.map +1 -0
  91. package/dist/kit/geometry.d.ts +13 -0
  92. package/dist/kit/geometry.d.ts.map +1 -0
  93. package/dist/kit/geometry.js +54 -0
  94. package/dist/kit/geometry.js.map +1 -0
  95. package/dist/kit/graph.d.ts +46 -0
  96. package/dist/kit/graph.d.ts.map +1 -0
  97. package/dist/kit/graph.js +90 -0
  98. package/dist/kit/graph.js.map +1 -0
  99. package/dist/kit/mark.d.ts +72 -0
  100. package/dist/kit/mark.d.ts.map +1 -0
  101. package/dist/kit/mark.js +87 -0
  102. package/dist/kit/mark.js.map +1 -0
  103. package/dist/kit/part-fills.d.ts +23 -0
  104. package/dist/kit/part-fills.d.ts.map +1 -0
  105. package/dist/kit/part-fills.js +46 -0
  106. package/dist/kit/part-fills.js.map +1 -0
  107. package/dist/kit/place.d.ts +20 -0
  108. package/dist/kit/place.d.ts.map +1 -0
  109. package/dist/kit/place.js +66 -0
  110. package/dist/kit/place.js.map +1 -0
  111. package/dist/kit/sampler.d.ts +17 -0
  112. package/dist/kit/sampler.d.ts.map +1 -0
  113. package/dist/kit/sampler.js +250 -0
  114. package/dist/kit/sampler.js.map +1 -0
  115. package/dist/kit/scale.d.ts +12 -0
  116. package/dist/kit/scale.d.ts.map +1 -0
  117. package/dist/kit/scale.js +37 -0
  118. package/dist/kit/scale.js.map +1 -0
  119. package/dist/kit/source.d.ts +22 -0
  120. package/dist/kit/source.d.ts.map +1 -0
  121. package/dist/kit/source.js +45 -0
  122. package/dist/kit/source.js.map +1 -0
  123. package/dist/kit/system.d.ts +31 -0
  124. package/dist/kit/system.d.ts.map +1 -0
  125. package/dist/kit/system.js +71 -0
  126. package/dist/kit/system.js.map +1 -0
  127. package/dist/kit/ticks.d.ts +19 -0
  128. package/dist/kit/ticks.d.ts.map +1 -0
  129. package/dist/kit/ticks.js +78 -0
  130. package/dist/kit/ticks.js.map +1 -0
  131. package/dist/kit/withdrawn.d.ts +9 -0
  132. package/dist/kit/withdrawn.d.ts.map +1 -0
  133. package/dist/kit/withdrawn.js +9 -0
  134. package/dist/kit/withdrawn.js.map +1 -0
  135. package/dist/marks/curve-area.d.ts +51 -0
  136. package/dist/marks/curve-area.d.ts.map +1 -0
  137. package/dist/marks/curve-area.js +59 -0
  138. package/dist/marks/curve-area.js.map +1 -0
  139. package/dist/marks/drop-lines.d.ts +57 -0
  140. package/dist/marks/drop-lines.d.ts.map +1 -0
  141. package/dist/marks/drop-lines.js +43 -0
  142. package/dist/marks/drop-lines.js.map +1 -0
  143. package/dist/marks/plot-point.d.ts +71 -0
  144. package/dist/marks/plot-point.d.ts.map +1 -0
  145. package/dist/marks/plot-point.js +71 -0
  146. package/dist/marks/plot-point.js.map +1 -0
  147. package/dist/marks/riemann-sum.d.ts +58 -0
  148. package/dist/marks/riemann-sum.d.ts.map +1 -0
  149. package/dist/marks/riemann-sum.js +63 -0
  150. package/dist/marks/riemann-sum.js.map +1 -0
  151. package/dist/marks/tangent-line.d.ts +71 -0
  152. package/dist/marks/tangent-line.d.ts.map +1 -0
  153. package/dist/marks/tangent-line.js +89 -0
  154. package/dist/marks/tangent-line.js.map +1 -0
  155. package/dist/marks/vector-arrow.d.ts +60 -0
  156. package/dist/marks/vector-arrow.d.ts.map +1 -0
  157. package/dist/marks/vector-arrow.js +67 -0
  158. package/dist/marks/vector-arrow.js.map +1 -0
  159. package/dist/nodes.d.ts +43 -0
  160. package/dist/nodes.d.ts.map +1 -0
  161. package/dist/nodes.js +57 -0
  162. package/dist/nodes.js.map +1 -0
  163. package/dist/plots/function-plot.d.ts +159 -0
  164. package/dist/plots/function-plot.d.ts.map +1 -0
  165. package/dist/plots/function-plot.js +184 -0
  166. package/dist/plots/function-plot.js.map +1 -0
  167. package/dist/plots/points-plot.d.ts +64 -0
  168. package/dist/plots/points-plot.d.ts.map +1 -0
  169. package/dist/plots/points-plot.js +72 -0
  170. package/dist/plots/points-plot.js.map +1 -0
  171. package/dist/plots/stream-lines.d.ts +76 -0
  172. package/dist/plots/stream-lines.d.ts.map +1 -0
  173. package/dist/plots/stream-lines.js +122 -0
  174. package/dist/plots/stream-lines.js.map +1 -0
  175. package/dist/plots/traced-path.d.ts +70 -0
  176. package/dist/plots/traced-path.d.ts.map +1 -0
  177. package/dist/plots/traced-path.js +41 -0
  178. package/dist/plots/traced-path.js.map +1 -0
  179. package/dist/plots/vector-field.d.ts +60 -0
  180. package/dist/plots/vector-field.d.ts.map +1 -0
  181. package/dist/plots/vector-field.js +77 -0
  182. package/dist/plots/vector-field.js.map +1 -0
  183. package/dist/structures/graph-layout.d.ts +11 -0
  184. package/dist/structures/graph-layout.d.ts.map +1 -0
  185. package/dist/structures/graph-layout.js +135 -0
  186. package/dist/structures/graph-layout.js.map +1 -0
  187. package/dist/structures/network-graph.d.ts +174 -0
  188. package/dist/structures/network-graph.d.ts.map +1 -0
  189. package/dist/structures/network-graph.js +240 -0
  190. package/dist/structures/network-graph.js.map +1 -0
  191. package/dist/structures/sample-space.d.ts +114 -0
  192. package/dist/structures/sample-space.d.ts.map +1 -0
  193. package/dist/structures/sample-space.js +161 -0
  194. package/dist/structures/sample-space.js.map +1 -0
  195. package/dist/systems/axes2d.d.ts +197 -0
  196. package/dist/systems/axes2d.d.ts.map +1 -0
  197. package/dist/systems/axes2d.js +157 -0
  198. package/dist/systems/axes2d.js.map +1 -0
  199. package/dist/systems/number-line.d.ts +101 -0
  200. package/dist/systems/number-line.d.ts.map +1 -0
  201. package/dist/systems/number-line.js +91 -0
  202. package/dist/systems/number-line.js.map +1 -0
  203. package/dist/systems/number-plane.d.ts +168 -0
  204. package/dist/systems/number-plane.d.ts.map +1 -0
  205. package/dist/systems/number-plane.js +186 -0
  206. package/dist/systems/number-plane.js.map +1 -0
  207. package/dist/systems/polar-plane.d.ts +98 -0
  208. package/dist/systems/polar-plane.d.ts.map +1 -0
  209. package/dist/systems/polar-plane.js +139 -0
  210. package/dist/systems/polar-plane.js.map +1 -0
  211. package/dist/tex/geometry.d.ts +85 -0
  212. package/dist/tex/geometry.d.ts.map +1 -0
  213. package/dist/tex/geometry.js +632 -0
  214. package/dist/tex/geometry.js.map +1 -0
  215. package/dist/tex/index.d.ts +11 -0
  216. package/dist/tex/index.d.ts.map +1 -0
  217. package/dist/tex/index.js +10 -0
  218. package/dist/tex/index.js.map +1 -0
  219. package/dist/tex/mathjax.d.ts +33 -0
  220. package/dist/tex/mathjax.d.ts.map +1 -0
  221. package/dist/tex/mathjax.js +74 -0
  222. package/dist/tex/mathjax.js.map +1 -0
  223. package/dist/tex/matrix.d.ts +101 -0
  224. package/dist/tex/matrix.d.ts.map +1 -0
  225. package/dist/tex/matrix.js +56 -0
  226. package/dist/tex/matrix.js.map +1 -0
  227. package/dist/tex/node.d.ts +98 -0
  228. package/dist/tex/node.d.ts.map +1 -0
  229. package/dist/tex/node.js +25 -0
  230. package/dist/tex/node.js.map +1 -0
  231. package/dist/tex/tween.d.ts +50 -0
  232. package/dist/tex/tween.d.ts.map +1 -0
  233. package/dist/tex/tween.js +253 -0
  234. package/dist/tex/tween.js.map +1 -0
  235. package/dist/tex/typeset.d.ts +133 -0
  236. package/dist/tex/typeset.d.ts.map +1 -0
  237. package/dist/tex/typeset.js +403 -0
  238. package/dist/tex/typeset.js.map +1 -0
  239. package/dist/three/axes3d.d.ts +247 -0
  240. package/dist/three/axes3d.d.ts.map +1 -0
  241. package/dist/three/axes3d.js +187 -0
  242. package/dist/three/axes3d.js.map +1 -0
  243. package/dist/three/curve-plot3d.d.ts +126 -0
  244. package/dist/three/curve-plot3d.d.ts.map +1 -0
  245. package/dist/three/curve-plot3d.js +109 -0
  246. package/dist/three/curve-plot3d.js.map +1 -0
  247. package/dist/three/entries.d.ts +17 -0
  248. package/dist/three/entries.d.ts.map +1 -0
  249. package/dist/three/entries.js +15 -0
  250. package/dist/three/entries.js.map +1 -0
  251. package/dist/three/label3d.d.ts +11 -0
  252. package/dist/three/label3d.d.ts.map +1 -0
  253. package/dist/three/label3d.js +42 -0
  254. package/dist/three/label3d.js.map +1 -0
  255. package/dist/three/plot-point3d.d.ts +99 -0
  256. package/dist/three/plot-point3d.d.ts.map +1 -0
  257. package/dist/three/plot-point3d.js +34 -0
  258. package/dist/three/plot-point3d.js.map +1 -0
  259. package/dist/three/space.d.ts +43 -0
  260. package/dist/three/space.d.ts.map +1 -0
  261. package/dist/three/space.js +58 -0
  262. package/dist/three/space.js.map +1 -0
  263. package/dist/three/surface-plot3d.d.ts +207 -0
  264. package/dist/three/surface-plot3d.d.ts.map +1 -0
  265. package/dist/three/surface-plot3d.js +261 -0
  266. package/dist/three/surface-plot3d.js.map +1 -0
  267. package/dist/three/vector-arrow3d.d.ts +96 -0
  268. package/dist/three/vector-arrow3d.d.ts.map +1 -0
  269. package/dist/three/vector-arrow3d.js +53 -0
  270. package/dist/three/vector-arrow3d.js.map +1 -0
  271. package/package.json +80 -3
  272. package/registry.json +251 -0
  273. package/src/annotate/angle-mark.ts +137 -0
  274. package/src/annotate/curly-brace.ts +148 -0
  275. package/src/annotate/emphasis-mark.ts +118 -0
  276. package/src/engine.ts +86 -0
  277. package/src/index.ts +29 -0
  278. package/src/kit/brace.ts +37 -0
  279. package/src/kit/cache.ts +61 -0
  280. package/src/kit/component.ts +57 -0
  281. package/src/kit/contour.ts +94 -0
  282. package/src/kit/coords.ts +278 -0
  283. package/src/kit/curve.ts +47 -0
  284. package/src/kit/equation.ts +181 -0
  285. package/src/kit/equation3d.ts +137 -0
  286. package/src/kit/expression.ts +159 -0
  287. package/src/kit/field-mark.ts +171 -0
  288. package/src/kit/field.ts +50 -0
  289. package/src/kit/follow.ts +229 -0
  290. package/src/kit/furniture.ts +113 -0
  291. package/src/kit/geometry.ts +49 -0
  292. package/src/kit/graph.ts +116 -0
  293. package/src/kit/mark.ts +152 -0
  294. package/src/kit/part-fills.ts +61 -0
  295. package/src/kit/place.ts +77 -0
  296. package/src/kit/sampler.ts +281 -0
  297. package/src/kit/scale.ts +39 -0
  298. package/src/kit/source.ts +57 -0
  299. package/src/kit/system.ts +105 -0
  300. package/src/kit/ticks.ts +85 -0
  301. package/src/kit/withdrawn.ts +8 -0
  302. package/src/marks/curve-area.ts +89 -0
  303. package/src/marks/drop-lines.ts +71 -0
  304. package/src/marks/plot-point.ts +102 -0
  305. package/src/marks/riemann-sum.ts +99 -0
  306. package/src/marks/tangent-line.ts +119 -0
  307. package/src/marks/vector-arrow.ts +98 -0
  308. package/src/nodes.ts +99 -0
  309. package/src/plots/function-plot.ts +220 -0
  310. package/src/plots/points-plot.ts +103 -0
  311. package/src/plots/stream-lines.ts +160 -0
  312. package/src/plots/traced-path.ts +70 -0
  313. package/src/plots/vector-field.ts +107 -0
  314. package/src/structures/graph-layout.ts +145 -0
  315. package/src/structures/network-graph.ts +291 -0
  316. package/src/structures/sample-space.ts +210 -0
  317. package/src/systems/axes2d.ts +226 -0
  318. package/src/systems/number-line.ts +130 -0
  319. package/src/systems/number-plane.ts +232 -0
  320. package/src/systems/polar-plane.ts +177 -0
  321. package/src/tex/geometry.ts +703 -0
  322. package/src/tex/index.ts +15 -0
  323. package/src/tex/mathjax.ts +82 -0
  324. package/src/tex/matrix.ts +97 -0
  325. package/src/tex/node.ts +74 -0
  326. package/src/tex/tween.ts +308 -0
  327. package/src/tex/typeset.ts +461 -0
  328. package/src/three/axes3d.ts +267 -0
  329. package/src/three/curve-plot3d.ts +146 -0
  330. package/src/three/entries.ts +42 -0
  331. package/src/three/label3d.ts +52 -0
  332. package/src/three/plot-point3d.ts +63 -0
  333. package/src/three/space.ts +92 -0
  334. package/src/three/surface-plot3d.ts +318 -0
  335. package/src/three/vector-arrow3d.ts +88 -0
package/README.md CHANGED
@@ -1,3 +1,390 @@
1
- # Temporary Holding Version
1
+ # @motionscript/math
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Math for [Motion Script](https://motionscript.dev): coordinate systems whose
4
+ children sit in graph coordinates, plots of equations, the marks that go on a
5
+ graph, and typeset formulas that morph into one another.
6
+
7
+ Hand the kit's nodes to the engine through your project entry's `nodes`, and any
8
+ document that engine opens can name them by key:
9
+
10
+ ```ts
11
+ // src/project.ts
12
+ import { NODES } from '@motionscript/math';
13
+
14
+ export const nodes = NODES;
15
+ ```
16
+
17
+ ## Exports
18
+
19
+ | Entry | Holds |
20
+ | --- | --- |
21
+ | `@motionscript/math` | Every component, `NODES`, and the kit below |
22
+ | `@motionscript/math/kit` | What the nodes share and a copied node imports rather than copies: the systems' and marks' helpers (`systemLayout`, `traced`, `drawMark`, the plane a system hands its marks), the coordinate map, the equation language, the sampler, and the LaTeX helpers |
23
+ | `@motionscript/math/tex` | The typeset-math half alone: `Latex`, `TEX_NODES` and its helpers |
24
+
25
+ ## Nodes
26
+
27
+ Every node also has the shape commands (`moveTo`, `fadeTo`, `fillTo`,
28
+ `strokeTo`, `progressTo`, …).
29
+
30
+ | Key | What it is | Goes in | Own commands |
31
+ | --- | --- | --- | --- |
32
+ | `numberLine` | One axis with ticks and numbers | anywhere | `rangeTo({ range })` |
33
+ | `axes2d` | An x and a y axis, linear or log | anywhere | `rangeTo({ xRange, yRange })` |
34
+ | `numberPlane` | Axes over a full grid, square units | anywhere | `rangeTo`, `transformTo({ matrix })`, `warpTo({ warp })` |
35
+ | `polarPlane` | Rings and spokes about an origin | anywhere | `rangeTo({ radius })` |
36
+ | `functionPlot` | The curve of an equation | a system | `morphTo({ expression })`, `paramsTo({ params })`, `domainTo({ domain })` |
37
+ | `pointsPlot` | A line or closed shape through listed graph points | a system | `pointsTo({ points })` |
38
+ | `plotPoint` | A labelled dot, free or riding a plot | a system or a `functionPlot` | |
39
+ | `vectorArrow` | An arrow from `tail` to `head` | a system | `endpointsTo({ tail, head })` |
40
+ | `curveArea` | The region under a plot, or between two | a system, beside a `functionPlot` | `domainTo({ domain })` |
41
+ | `riemannSum` | Rectangles approximating that region | a system, beside a `functionPlot` | `refineTo({ dx })`, `domainTo({ domain })` |
42
+ | `tangentLine` | The tangent to a plot, or a secant with its run and rise | a `functionPlot` | |
43
+ | `dropLines` | Guides from a graph point to the axes | a system or a `functionPlot` | |
44
+ | `latex` | A typeset formula with nameable parts | anywhere | `morphTo({ latex })`, `partFillTo({ part, fill })`, `writeTo({ written })` |
45
+ | `latexMatrix` | A matrix typeset from its entries | anywhere | `entriesTo({ entries })`, and a formula's |
46
+ | `curlyBrace` | A brace along a node, a part of a formula, or two points | anywhere | `retargetTo({ on, part })` |
47
+ | `emphasisMark` | A box, circle, underline or cross on a node or a part | anywhere | `retargetTo({ on, part })` |
48
+ | `angleMark` | An angle's arc or square, with its label | anywhere | `radiusTo({ radius })` |
49
+ | `axes3d` | A 3D graph: three axes through a box of graph coordinates, z up, seen through its own camera | anywhere 2D (it is a `canvas3d`) | `rangeTo({ xRange, yRange, zRange })`, and a `canvas3d`'s `orbitTo` |
50
+ | `surfacePlot3d` | A surface: a height over x and y, or three parts in u and v | an `axes3d` | `morphTo({ expression })`, `paramsTo({ params })`, `domainTo({ uDomain, vDomain })` |
51
+ | `curvePlot3d` | A curve through space, three parts in t | an `axes3d` | `morphTo`, `paramsTo`, `domainTo({ domain })`, `progressTo({ start, end })` |
52
+ | `plotPoint3d` | A labelled dot, free or riding a surface | an `axes3d` or a `surfacePlot3d` | |
53
+ | `vectorArrow3d` | An arrow from `tail` to `head` | an `axes3d` | `endpointsTo({ tail, head })` |
54
+ | `vectorField` | A grid of arrows showing a field, `(P, Q)` in x and y | a system | `morphTo({ expression })`, `paramsTo({ params })` |
55
+ | `streamLines` | The lines a field carries a point along | a system | `flowTo({ phase })`, `morphTo`, `paramsTo` |
56
+ | `tracedPath` | The trail a point leaves as a value changes | a system | `traceTo({ value })`, and a plot's |
57
+ | `networkGraph` | Vertices and edges, arranged in a circle, by springs, as a tree or in a grid | anywhere | `arrangeTo({ arrangement })`, `partFillTo({ part, fill })` |
58
+ | `sampleSpace` | A probability's whole cut into parts whose areas are their probabilities | anywhere | `divideTo({ columnShares, rowShares })` |
59
+
60
+ A system is a `numberLine`, an `axes2d`, a `numberPlane` or a `polarPlane`. The
61
+ Goes in column is where each node is made to go; offering it only there is the
62
+ host's to do, since the engine is told only a node's key, entries and commands.
63
+ Nothing checks it when a document builds: a plot outside a system builds and
64
+ draws nothing.
65
+
66
+ Each node takes only the paints it draws. A node spreads the shape paints
67
+ (`fill`, `stroke` and the outline trim `start`, `end`, `progressTo`, `flash`) it
68
+ has a use for and leaves the rest out, so they are not offered: a plot, a tangent, an arrow or a brace is a line with
69
+ no fill; an area is a fill with no outline; a field is one stroke for every arrow
70
+ or line; a formula and a traced path reveal themselves (`writeTo`, `traceTo`)
71
+ rather than by trimming; a dot, a sample space and a Riemann sum have nothing a
72
+ trim would draw on. `shadow` stays on all of them.
73
+
74
+ ## Coordinate systems
75
+
76
+ ```ts
77
+ const document = {
78
+ kind: 'composition',
79
+ variables: [{ id: 't', value: 0 }],
80
+ nodes: [
81
+ { id: 'axes', type: 'axes2d', parentId: null, layerOrder: 0,
82
+ props: { width: 800, height: 450, xRange: [-4, 4], yRange: [-2, 2], fontFamily: 'Inter' } },
83
+ { id: 'curve', type: 'functionPlot', parentId: 'axes', layerOrder: 0, props: { expression: 'sin(x)' } },
84
+ { id: 'dot', type: 'plotPoint', parentId: 'curve', layerOrder: 0, props: { x: '=[t]' } },
85
+ { id: 'note', type: 'text', parentId: 'axes', layerOrder: 1,
86
+ props: { x: 2, y: 1.5, text: 'y = sin x', fontSize: 24, fontFamily: 'Inter', fill: 'white' } },
87
+ ],
88
+ commands: [
89
+ { id: 'a', type: 'progressTo', targetId: 'curve', at: 0, duration: 1, args: { end: 1 } },
90
+ { id: 'b', type: 'variableTo', targetId: 't', at: 1, duration: 2, args: { value: 3.14 } },
91
+ { id: 'c', type: 'rangeTo', targetId: 'axes', at: 3, duration: 1, args: { xRange: [0, 8] } },
92
+ ],
93
+ };
94
+ ```
95
+
96
+ - **A child's `x`/`y` are graph units, whatever the child is.** A text, an image
97
+ or a shape dropped in a system sits at graph coordinates and keeps its own
98
+ size; `moveTo` moves it in graph units; a range tween carries it. On a
99
+ `numberLine`, `x` is a value on the line and `y` is pixels above it.
100
+ - **A mark is drawn through the system's map.** `functionPlot`, `pointsPlot`,
101
+ `vectorArrow`, `curveArea`, `riemannSum`, `tangentLine` and `dropLines` are
102
+ marks (`traced`): their geometry is in graph coordinates and their box is the tight box of
103
+ their ink. A plot's or an arrow's own `x`/`y` shift it in graph units; a
104
+ `tangentLine`'s and a `dropLines`'s `x` is where along the graph they are.
105
+ Outside a system a graph unit is a pixel and a plot draws nothing.
106
+ - **Riding a plot.** A `plotPoint`, `tangentLine` or `dropLines` inside a
107
+ `functionPlot` follows that plot, appears, moves and leaves with it, and is
108
+ drawn over the curve: a mark's stroke is its ink, painted before its children
109
+ rather than last as a shape's outline is (a mark drawn with `drawMark` that
110
+ strokes its ink its own way passes its own `ink`). In the system instead, a
111
+ point or guide names a plot by id in `on`, or none and is free. `curveArea`
112
+ and `riemannSum` sit in the system beside the plots they read and name one in
113
+ `on` (an area a second in `under`). A point that rides a plot
114
+ takes its height from the curve and keeps its own `y` only where the curve has
115
+ no value.
116
+ - **One value drives a scene through a variable.** Bind any graph prop with
117
+ `"=[t]"` and animate `t` with `variableTo`; a formula may sit at any depth, so
118
+ a `pointsPlot` corner can be `{ x: '=[t]', y: '=25/[t]' }`. `plotPoint.value`
119
+ and `tangentLine.slope` can be read back as `[key.value]` and `[key.slope]`.
120
+ - **A system's `stroke` is its axis line and its `fill` its backdrop.** So
121
+ `stroke.endCap` is the axis tip. Ticks, grid lines and numbers are drawn by the
122
+ system itself; they are not child nodes. Drawn on with `progressTo`, the ticks
123
+ and numbers appear as the line reaches them.
124
+ - **Numbers need a font.** A system's `fontFamily` is empty by default, which
125
+ takes the scene's default text style; a scene with none has to set it, as any
126
+ text does.
127
+ - **An axis crosses the other at its zero**, or at the nearest edge when zero is
128
+ out of range or the other axis is logarithmic. A `step` of `0` picks a tidy
129
+ spacing for the axis's length; a log axis is marked at the powers of ten.
130
+
131
+ ## 3D graphs
132
+
133
+ ```ts
134
+ nodes: [
135
+ { id: 'axes', type: 'axes3d', parentId: null, layerOrder: 0, props: { width: 960, height: 540, labels: true, fontFamily: 'Inter' } },
136
+ { id: 'bump', type: 'surfacePlot3d', parentId: 'axes', layerOrder: 0,
137
+ props: { expression: '1.8 exp(-(x^2 + y^2) / 2)', colorScale: ['#1d4ed8', '#22c55e', '#facc15', '#ef4444'] } },
138
+ { id: 'dot', type: 'plotPoint3d', parentId: 'bump', layerOrder: 0, props: { x: 0.8, y: -0.6, label: 'P' } },
139
+ ],
140
+ commands: [
141
+ { id: 'a', type: 'orbitTo', targetId: 'axes', at: 0, duration: 2, args: { orbit: 80, elevation: 32 } },
142
+ { id: 'b', type: 'morphTo', targetId: 'bump', at: 2, duration: 1, args: { expression: '(x^2 - y^2) / 5' } },
143
+ ],
144
+ ```
145
+
146
+ - **A 3D graph is right-handed with z up.** The scene has y up, so graph x, y and
147
+ z run along the scene's z, x and y: seen head-on, y is to the right and z is
148
+ up, and the axes' default camera shows x coming toward the viewer.
149
+ - **An `axes3d` is its own viewport.** It is a `canvas3d` (camera, lights,
150
+ `orbitTo`, a box on the stage), so it needs no canvas around it and cannot go
151
+ inside one; a 3D shape you want beside the graph goes inside it instead.
152
+ - **The axes are a box, `xLength` by `yLength` by `zLength` scene units, centred
153
+ in the scene**, showing the three ranges. An axis crosses the others at their
154
+ zero, or at the nearest end of a range without one.
155
+ - **A child's `x`/`y`/`z` are graph units, whatever the child is**, and it keeps
156
+ its own size and turn: a `sphere3d` at `x: 1, y: 2, z: 0.5` sits at that graph
157
+ point, the built-in `moveTo` moves it in graph units, and `rangeTo` carries it.
158
+ - **A surface is held inside the axes.** A height that leaves the z range is
159
+ drawn at its edge, and one with no value is drawn flat, so a pole does not tear
160
+ the mesh. Left out, `uDomain` and `vDomain` are the axes' x and y ranges for a
161
+ height and 0 to 1 for a parametric surface.
162
+ - **A point put inside a surface rides it**: its `x` and `y` say where, and its
163
+ height is the surface's, which `surfaceValueAt(surface, x, y)` reads.
164
+ - **`colorScale` colours a surface by height** over the axes' z range, lowest
165
+ first; without one it is painted in its `fill`, the plot blue unless given one
166
+ (a `curvePlot3d` too). `meshLines` rules it each way.
167
+ - **A surface takes the mesh material props** (`opacity`, `roughness`, `wireframe`,
168
+ …) and is lit by the axes' lights; it is drawn from both sides.
169
+ - **Lines are tubes and labels are cards.** A `curvePlot3d`'s and an axis's
170
+ `thickness`, a point's `radius` and a label's `labelSize` are scene units, so
171
+ they keep their size when a range changes. A label always faces the camera.
172
+ - **Moving the camera** is the canvas's `orbitTo({ orbit, elevation, zoom })`, or a
173
+ `camera3d`'s `orbitTo` and `lookTo` when the scene has one.
174
+
175
+ | Written as | Is | Variables |
176
+ | --- | --- | --- |
177
+ | `sin(x) * cos(y)`, `z = x^2 - y^2` | a surface, as a height | `x`, `y` |
178
+ | `(cos(u) sin(v), sin(u) sin(v), cos(v))` | a parametric surface | `u`, `v` |
179
+ | `(cos(t), sin(t), t / 4)` | a space curve | `t` |
180
+
181
+ Any other name is a named value, as in a 2D plot (`surfaceParams`,
182
+ `spaceCurveParams`); `surfaceError` and `spaceCurveError` say why text will not draw.
183
+
184
+ ## Equations
185
+
186
+ A `functionPlot`'s `expression` is read the way it is written:
187
+
188
+ | Written as | Is | Free variable, `domain` when not given |
189
+ | --- | --- | --- |
190
+ | `sin(x)`, `y = sin(x)` | a function of `x` | `x`, the system's width |
191
+ | `x = y^2` | a function of `y` | `y`, the system's height |
192
+ | `r = 1 + cos(theta)` | polar | `theta`, one turn |
193
+ | `(cos(t), sin(t))` | parametric | `t`, 0 to 1 |
194
+ | `x^2 + y^2 = 4` | implicit | drawn where it holds, over what the system shows |
195
+
196
+ - **The language is the engine's expression grammar under its own dialect**:
197
+ bare names, trig in radians, `ln`, `log2`, `log10`, the hyperbolics, and the
198
+ constants `pi`, `e`, `tau`, `phi`. Implicit multiplication (`2x`, `2(x + 1)`)
199
+ and `^` work as in a document formula. It never evaluates text as code.
200
+ - **A name the equation does not know is a named value**, held in `params`:
201
+ `{ expression: 'a * sin(k * x)', params: { a: 2, k: '=[speed]' } }`. One left
202
+ unset is 1, so an equation draws as soon as it is written; `equationParams(source)`
203
+ lists them for a host that draws a field for each. `paramsTo` animates them.
204
+ - **`morphTo` bends one curve into another**, of any kind into any kind: the two
205
+ are blended point for point along their parameters.
206
+ - **Text that is not an equation draws nothing** and throws nothing, so a host can
207
+ commit on every keystroke; `equationError(source)` gives the reason.
208
+ - **A curve is sampled adaptively** and broken at an asymptote or the edge of its
209
+ domain, so `1/x`, `tan(x)` and `sqrt(x)` draw as they should.
210
+
211
+ ## Planes, fields and trails
212
+
213
+ - **A number plane can be transformed.** `matrix` (`[[a, b], [c, d]]`, or flat)
214
+ sends every point of the plane through a linear map about its origin, and
215
+ `warp` (two parts in x and y, `(x + sin(y), y + sin(x))`) bends it by a
216
+ function of its own points. The grid, the axes and everything on the plane go
217
+ with it: a child's position, a plot's curve, a vector's ends. `transformTo`
218
+ and `warpTo` animate them, each point travelling straight to where it ends up,
219
+ and `warpTo({ warp: "" })` flattens the plane again. While it is transformed
220
+ the plane leaves its flat self behind, faintly (`ghost`). The grid is ruled
221
+ over whatever of the plane then falls in the box, up to four times its own
222
+ ranges, so it stays full under a turn, a shear or a fourfold shrink, and a
223
+ plane squeezed onto a line folds its grid into a narrowing band.
224
+ - **A polar plane is a plane with another ruling.** Its children are still at x
225
+ and y, in the units its rings count, so `r = 1 + cos(theta)` in a
226
+ `functionPlot`, a point or an arrow goes on it as on axes. `radius` is its
227
+ outer ring, `spokes` how many divide the turn, and `angleUnit` writes them in
228
+ degrees or as fractions of π.
229
+ - **An implicit equation is drawn where it holds.** `x^2 + y^2 = 4` in a
230
+ `functionPlot` is traced over what the system shows. It has no parameter to
231
+ bend along, so a morph to or from one changes over half way.
232
+ - **A field is two parts in x and y**, `(-y, x)`. A `vectorField` centres an
233
+ arrow on each point of a grid `spacing` apart, as long as the field is strong
234
+ there times `arrowScale` and never longer than the spacing; a `streamLines`
235
+ follows the field from each of those points for `length` graph units. With a
236
+ list of `strengthFills` both are painted by the field's strength, weakest
237
+ first; without one, in the stroke's own paint.
238
+ `streamLines.window` shows a stretch of each line and `flowTo({ phase })` sends
239
+ the stretches along: one whole turn of `phase` runs every line end to end.
240
+ - **A traced path is a plot whose end follows a value.** It draws its equation
241
+ from `from` to `value`; bind `value` to a variable (`"=[t]"`) and the trail
242
+ grows as the variable is driven, or drive it with `traceTo({ value })`. `tail`
243
+ keeps only its most recent stretch.
244
+
245
+ ## Graphs and sample spaces
246
+
247
+ - **A network graph is its `vertices` (names) and `edges` (`{ from, to }`, or
248
+ pairs).** Its `fill` paints the vertices and its `stroke` the edges; with
249
+ `directed` each edge ends in an arrowhead, and an edge each way between two
250
+ vertices bows apart. Labels are the vertices' names.
251
+ - **`arrangement` places the vertices**: `circular` (the first at the top,
252
+ clockwise), `spring` (edges pull, every pair pushes; the same every time),
253
+ `tree` (levels down from `root`, a parent over its children), `grid`. A vertex
254
+ in `positions` is placed by hand, from -1 to 1 each way. `arrangeTo` moves every
255
+ vertex to where another arrangement puts it. (`layout` is every node's own box,
256
+ hence the other word.) `vertexPoints(graph, size)` says where each vertex is drawn.
257
+ - **`partFillTo({ part, fill })` paints a vertex by its name, or an edge written
258
+ `a-b`**, arriving over the graph's own paint, as a formula's parts are painted;
259
+ `partFills` holds them.
260
+ - **A sample space's `columnShares` cut it across** (any numbers, read as shares
261
+ of their sum) **and each column's entry in `rowShares` cuts that column**
262
+ (its upper share, 0 to 1), so each part's area is its probability. Braces name
263
+ the columns below (`columnLabels`) and the rows on the left (`rowLabels`);
264
+ `values` writes each part's probability in it; `divideTo` moves the cuts.
265
+ `sampleParts(space, size)` gives each part's box and probability.
266
+
267
+ ## Annotations
268
+
269
+ `curlyBrace`, `emphasisMark` (box, circle, underline, cross) and `angleMark`
270
+ work anywhere, not only on a graph. A brace or an emphasis mark names a node
271
+ in `on`, and optionally one `part` of a formula, and is drawn on it wherever
272
+ the two are in the tree; `retargetTo` slides it to another. A brace with no
273
+ `on` spans `tail` to `head`. An angle mark sits at its own position and sweeps
274
+ `fromAngle` to `toAngle` in degrees, so binding one to a variable opens it.
275
+ A label written between dollar signs is typeset, on these and on a plot point
276
+ or an axis. `FOLLOW_STATE`, `FOLLOW_COMMANDS` and `followedQuad` in
277
+ `@motionscript/math/kit` are what a custom mark of this kind is built on.
278
+
279
+ ## Latex
280
+
281
+ The formulas below were published as `@motionscript/latex` up to
282
+ `0.1.0-alpha.3`; that package is no longer updated, and the same node, key and
283
+ exports are here.
284
+
285
+ ```ts
286
+ import type { CompositionDocument } from '@motionscript/sdk';
287
+
288
+ export default {
289
+ kind: 'composition',
290
+ nodes: [
291
+ { id: 'eq', type: 'latex', parentId: null, layerOrder: 0,
292
+ props: { latex: 'a^2 + b^2 = c^2', fontSize: 64, fill: 'white' } },
293
+ ],
294
+ commands: [
295
+ { id: 'solve', type: 'morphTo', targetId: 'eq', at: 0, duration: 1.2,
296
+ args: { latex: 'c = \\sqrt{a^2 + b^2}' } },
297
+ ],
298
+ } satisfies CompositionDocument;
299
+ ```
300
+
301
+ - **`Latex`** node, a component that draws a formula as fillable, strokable
302
+ glyph paths. Set `latex` to the TeX source and `fontSize` to scale it; `fill`,
303
+ `stroke`, `shadow`, and `padding` work like any other shape.
304
+ - **Formula morphing**: `morphTo` (or any `to` that names `latex`) interpolates each
305
+ glyph between the current and target formula, matching tokens that persist,
306
+ fading out tokens that leave, and fading in tokens that arrive. A persisting
307
+ glyph is carried by its geometry, so one that changes size on the way — the
308
+ `2` of `b^2` becoming the `2` of `2a`, or a symbol dropping into a `\frac` —
309
+ grows or shrinks across the transition instead of snapping. The hugging box
310
+ resizes smoothly along with it.
311
+ - **Parts**: every piece of the source is a part, named by that source
312
+ (`a^2`, `\frac{d}{dx}`, or neighbours that spell it together). `partFills`
313
+ and `partFillTo` paint one with any paint, `latexPartBounds(node, part)` says where it is,
314
+ and a morph carries a term both formulas write as one, with its fill.
315
+ - **`written`** writes the formula on glyph by glyph, each outlined and then
316
+ filled; `writeTo` animates it. It is how a formula appears, so a formula has
317
+ no outline trim (`start`, `end`, `progressTo`, `flash`).
318
+ - **`latexMatrix`** typesets `entries` in the `brackets` it is given. Each entry
319
+ is a part; `entriesTo` morphs to new ones.
320
+ - **`buildLatexPath(latex, fontSize)`**, the underlying helper that turns TeX
321
+ into positioned `LatexToken` glyph paths plus intrinsic size and bounds, for
322
+ callers that want the geometry directly.
323
+
324
+ TeX is parsed through MathJax with the `base`, `ams`, `boldsymbol`,
325
+ `newcommand`, `cancel`, `color`, `mhchem`, `physics`, `bbox`, and `mathtools`
326
+ packages enabled. Rendering is synchronous and browser-only.
327
+
328
+ A formula MathJax cannot typeset (`\frac{a`, `\fra`, a stray `{`, or `\require`,
329
+ since only the packages above are loaded) throws a `LatexError` from
330
+ `buildLatexPath`, and from a `Latex` node that holds it whenever it is laid out
331
+ (a document holding one fails to build). The error carries the `latex` source and MathJax's `reason`. It is the same
332
+ in a browser and in Node; nothing is drawn in place of the formula.
333
+
334
+ This package is written against [`@motionscript/sdk`](https://github.com/motionscript-dev/motionscript/tree/main/packages/sdk), which it
335
+ takes as a peer dependency, and renders through whatever backend draws the
336
+ scene, such as [`@motionscript/browser`](https://github.com/motionscript-dev/motionscript/tree/main/packages/browser).
337
+
338
+ ## Morphing, fills and what the host supplies
339
+
340
+ - **`morphTo({ latex })` is the document command, and every `to` of `latex` is a morph.**
341
+ Mid-tween `latex` (a matrix's `entries` and `brackets`) holds both ends, a
342
+ `Morph`, and the glyphs are drawn that far between them, so a seek to any time
343
+ draws the morph there. A `to` of `fontSize` alone sets the formula again at
344
+ each size. A morph reads its from-state on its **first evaluation**, not when
345
+ the command is built, so two morphs in sequence start the second from the
346
+ first's end.
347
+ - **Glyphs match by key.** A token's key is the character its MathJax glyph id
348
+ decodes to (a mathematical italic `𝑥` is not `x`); a rule or fraction bar is
349
+ `__rect_N` and a bare path `__path_N`, and those never match. `defaultLatexMorph`
350
+ pairs keys greedily in order, fades deleted tokens over the first half and added
351
+ ones over the second. A custom `morph` (`LatexStrategies`) replaces it, for a
352
+ node built on the typeset helpers, which take it as an argument
353
+ (`formulaFrame(source, fontSize, partFills, morph)`); a document cannot set it.
354
+ - **A `latex` row needs a `fill` or a `stroke` to draw anything**; `fill` defaults
355
+ to none. The formula is typeset in display style, so double each backslash inside
356
+ a JSON string.
357
+ - **MathJax loads only for a scene that typesets.** It and its default font,
358
+ including the `\mathbb`, `\mathcal`, `\mathfrak`, `\mathscr`, `\mathsf` and
359
+ `\mathtt` ranges, are bundled in a module of their own that `loadMathJax()`
360
+ imports once. A `latex` or `latexMatrix`, and a graph, a point, a brace or an
361
+ angle whose label is written between dollar signs, declares the
362
+ `math:mathjax` loader (`MATHJAX_LOADER`), which the host waits for before
363
+ layout; a scene with no formula never loads it. Until it is there a formula
364
+ draws nothing and is asked again. Code that typesets outside a scene (a tool, a
365
+ test) awaits `loadMathJax()` first: `buildLatexPath` throws `LatexNotLoaded`
366
+ before then, and `latexPartNames` answers with nothing.
367
+ - **Module state is shared per process**: one MathJax document, and two LRU memos
368
+ (typeset geometry by formula, 128 entries; paths by size and formula, 64).
369
+ Importing the module registers MathJax's HTML handler, with the DOM-free adaptor
370
+ when there is no `window` or `document`.
371
+ - **A copy of `latex` takes only `tex/node.ts`** (`registry.json`); typesetting, the
372
+ morph and the drawing (`tex/typeset.ts`) stay in this package behind `src/engine.ts`.
373
+
374
+ ## Usage
375
+
376
+ ```bash
377
+ npm install @motionscript/math @motionscript/sdk
378
+ ```
379
+
380
+ See the [docs](https://motionscript.dev/docs) for the full feature set and API
381
+ reference.
382
+
383
+ ## Development
384
+
385
+ From the monorepo root:
386
+
387
+ ```bash
388
+ pnpm --filter @motionscript/math build
389
+ pnpm --filter @motionscript/math test
390
+ ```
@@ -0,0 +1,96 @@
1
+ import { type Color, type NodeOf, type NormalizedColor, type PaintProps, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
2
+ export interface AngleMarkProps extends PaintProps {
3
+ fromAngle?: number;
4
+ toAngle?: number;
5
+ radius?: number;
6
+ corner?: "arc" | "square" | "auto";
7
+ label?: string;
8
+ labelSize?: number;
9
+ labelColor?: Color;
10
+ fontFamily?: string;
11
+ }
12
+ interface AngleValues {
13
+ readonly fromAngle: number;
14
+ readonly toAngle: number;
15
+ readonly radius: number;
16
+ readonly corner: "arc" | "square" | "auto";
17
+ }
18
+ /**
19
+ * The mark of an angle at the node's own position: an arc from one direction
20
+ * to another, or the small square of a right angle, with an optional label.
21
+ * Directions are degrees counter-clockwise from the right, so binding one to a
22
+ * variable opens and closes the angle. A label of `°` shows the angle's size.
23
+ */
24
+ export declare const AngleMark: import("@motionscript/sdk").Component<"angleMark", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
25
+ fromAngle: import("@motionscript/sdk").Type<number, number, false>;
26
+ toAngle: import("@motionscript/sdk").Type<number, number, false>;
27
+ radius: import("@motionscript/sdk").Type<number, number, false>;
28
+ /** `auto` draws the square where the angle is a right one. */
29
+ corner: import("@motionscript/sdk").Type<"auto" | "square" | "arc", "auto" | "square" | "arc", false>;
30
+ /** Text, a formula between dollar signs, or `°` for the angle's own size. */
31
+ label: import("@motionscript/sdk").Type<string, string, false>;
32
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
33
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
34
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
35
+ /** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */
36
+ value: import("@motionscript/sdk").Type<number, number, true>;
37
+ start: import("@motionscript/sdk").Type<number, number, false>;
38
+ end: import("@motionscript/sdk").Type<number, number, false>;
39
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
40
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
41
+ }>, {
42
+ readonly radiusTo: readonly ["radius"];
43
+ readonly strokeTo: readonly ["stroke"];
44
+ readonly shadowTo: readonly ["shadow"];
45
+ readonly progressTo: readonly ["start", "end"];
46
+ readonly flash: {
47
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
48
+ };
49
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
50
+ fromAngle: import("@motionscript/sdk").Type<number, number, false>;
51
+ toAngle: import("@motionscript/sdk").Type<number, number, false>;
52
+ radius: import("@motionscript/sdk").Type<number, number, false>;
53
+ /** `auto` draws the square where the angle is a right one. */
54
+ corner: import("@motionscript/sdk").Type<"auto" | "square" | "arc", "auto" | "square" | "arc", false>;
55
+ /** Text, a formula between dollar signs, or `°` for the angle's own size. */
56
+ label: import("@motionscript/sdk").Type<string, string, false>;
57
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
58
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
59
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
60
+ /** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */
61
+ value: import("@motionscript/sdk").Type<number, number, true>;
62
+ start: import("@motionscript/sdk").Type<number, number, false>;
63
+ end: import("@motionscript/sdk").Type<number, number, false>;
64
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
65
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
66
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
67
+ fromAngle: import("@motionscript/sdk").Type<number, number, false>;
68
+ toAngle: import("@motionscript/sdk").Type<number, number, false>;
69
+ radius: import("@motionscript/sdk").Type<number, number, false>;
70
+ /** `auto` draws the square where the angle is a right one. */
71
+ corner: import("@motionscript/sdk").Type<"auto" | "square" | "arc", "auto" | "square" | "arc", false>;
72
+ /** Text, a formula between dollar signs, or `°` for the angle's own size. */
73
+ label: import("@motionscript/sdk").Type<string, string, false>;
74
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
75
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
76
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
77
+ /** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */
78
+ value: import("@motionscript/sdk").Type<number, number, true>;
79
+ start: import("@motionscript/sdk").Type<number, number, false>;
80
+ end: import("@motionscript/sdk").Type<number, number, false>;
81
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
82
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
83
+ }>, {
84
+ readonly radiusTo: readonly ["radius"];
85
+ readonly strokeTo: readonly ["stroke"];
86
+ readonly shadowTo: readonly ["shadow"];
87
+ readonly progressTo: readonly ["start", "end"];
88
+ readonly flash: {
89
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
90
+ };
91
+ }, _Node2D<_Node2DProps>>>>;
92
+ export type AngleMark = NodeOf<typeof AngleMark>;
93
+ /** The angle a mark marks, in degrees: positive counter-clockwise. */
94
+ export declare function angleOf(s: Pick<AngleValues, "fromAngle" | "toAngle">): number;
95
+ export {};
96
+ //# sourceMappingURL=angle-mark.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"angle-mark.d.ts","sourceRoot":"","sources":["../../src/annotate/angle-mark.ts"],"names":[],"mappings":"AAAA,OAAO,E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,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,CAAC,GAAG,MAAM,CAE7E"}
@@ -0,0 +1,97 @@
1
+ import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
2
+ import { listed, omit, PAINT, PAINT_COMMANDS, painted } from "../kit/component.js";
3
+ import { outlineBounds, OWN_FRAME } from "../kit/follow.js";
4
+ import { drawLabels, loadFormulas } from "../kit/furniture.js";
5
+ import { strokeShape } from "../kit/mark.js";
6
+ /** Degrees of arc per drawn segment. */
7
+ const ARC_STEP = 4;
8
+ /** How close to a right angle `auto` draws the square. */
9
+ const RIGHT_SLOP = 0.5;
10
+ const point = (radius, degrees) => {
11
+ const turn = (degrees * Math.PI) / 180;
12
+ return { x: radius * Math.cos(turn), y: radius * Math.sin(turn) };
13
+ };
14
+ const state = {
15
+ // It is only an outline.
16
+ ...omit(PAINT, "fill"),
17
+ fromAngle: Types.number(0, { unit: "°" }),
18
+ toAngle: Types.number(60, { unit: "°" }),
19
+ radius: Types.number(48, { min: 0, unit: "px" }),
20
+ /** `auto` draws the square where the angle is a right one. */
21
+ corner: listed(["auto", "arc", "square"], "auto", { animatable: false }),
22
+ /** Text, a formula between dollar signs, or `°` for the angle's own size. */
23
+ label: Types.text("", { animatable: false }),
24
+ labelSize: Types.number(24, { min: 1, unit: "px" }),
25
+ labelColor: Types.color("#e5e7eb"),
26
+ fontFamily: Types.text("", { animatable: false }),
27
+ /** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */
28
+ value: Types.number(0, { private: true }),
29
+ };
30
+ /**
31
+ * The mark of an angle at the node's own position: an arc from one direction
32
+ * to another, or the small square of a right angle, with an optional label.
33
+ * Directions are degrees counter-clockwise from the right, so binding one to a
34
+ * variable opens and closes the angle. A label of `°` shows the angle's size.
35
+ */
36
+ export const AngleMark = component2d({
37
+ key: "angleMark",
38
+ state,
39
+ defaults: { stroke: { weight: 3, fill: "#e5e7eb", align: "center", cap: "round", join: "round" }, width: "hug", height: "hug", value: (s) => angleOf(s) },
40
+ load: (loader, s) => {
41
+ if (s.label !== "" && s.fontFamily !== "")
42
+ loader.font(s.fontFamily);
43
+ loadFormulas(loader, [s.label]);
44
+ },
45
+ commands: {
46
+ ...omit(PAINT_COMMANDS, "fillTo"),
47
+ /** Grow or shrink the mark. */
48
+ radiusTo: { args: ["radius"] },
49
+ },
50
+ measure: () => ({ width: 0, height: 0 }),
51
+ bounds: (_size, s) => outlineBounds(outline(s)),
52
+ render: (ctx, s) => {
53
+ const data = outline(s);
54
+ const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;
55
+ painted(ctx, () => {
56
+ if (shape)
57
+ ctx.draw(shape().shadow(s.shadow).fill([]));
58
+ if (s.label === "" || s.radius <= 0)
59
+ return;
60
+ const text = s.label === "°" ? `${Math.round(Math.abs(s.value) * 10) / 10}°` : s.label;
61
+ const at = point(s.radius + s.labelSize * 0.9, (s.fromAngle + s.toAngle) / 2);
62
+ const style = { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor };
63
+ ctx.draw(drawLabels([{ text, at, align: "center" }], style));
64
+ }, () => {
65
+ if (shape)
66
+ strokeShape(ctx, shape, s);
67
+ });
68
+ },
69
+ });
70
+ /** The angle a mark marks, in degrees: positive counter-clockwise. */
71
+ export function angleOf(s) {
72
+ return s.toAngle - s.fromAngle;
73
+ }
74
+ function outline({ fromAngle, toAngle, radius, corner }) {
75
+ const sweep = toAngle - fromAngle;
76
+ if (radius <= 0 || sweep === 0)
77
+ return [];
78
+ const square = corner === "square" || (corner === "auto" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);
79
+ if (square) {
80
+ const side = radius * 0.6;
81
+ const a = point(side, fromAngle);
82
+ const b = point(side, toAngle);
83
+ return [
84
+ { type: "M", x: a.x, y: a.y },
85
+ { type: "L", x: a.x + b.x, y: a.y + b.y },
86
+ { type: "L", x: b.x, y: b.y },
87
+ ];
88
+ }
89
+ const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));
90
+ const out = [];
91
+ for (let i = 0; i <= steps; i++) {
92
+ const p = point(radius, fromAngle + (sweep * i) / steps);
93
+ out.push({ type: i === 0 ? "M" : "L", x: p.x, y: p.y });
94
+ }
95
+ return out;
96
+ }
97
+ //# sourceMappingURL=angle-mark.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"angle-mark.js","sourceRoot":"","sources":["../../src/annotate/angle-mark.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAaR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAa1C,wCAAwC;AACxC,MAAM,QAAQ,GAAG,CAAC,CAAC;AACnB,0DAA0D;AAC1D,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,OAAe,EAAE,EAAE;IAC9C,MAAM,IAAI,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;IACvC,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;AACtE,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG;IACV,yBAAyB;IACzB,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,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QACzD,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import {\n component2d,\n Graphics2D,\n Types,\n type Color,\n type NodeOf,\n type NormalizedColor,\n type PaintProps,\n type PathCommand,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { listed, omit, PAINT, PAINT_COMMANDS, painted } from \"../kit/component\";\nimport { outlineBounds, OWN_FRAME } from \"../kit/follow\";\nimport { drawLabels, loadFormulas } from \"../kit/furniture\";\nimport { strokeShape } from \"../kit/mark\";\n\nexport interface AngleMarkProps extends PaintProps {\n fromAngle?: number;\n toAngle?: number;\n radius?: number;\n corner?: \"arc\" | \"square\" | \"auto\";\n label?: string;\n labelSize?: number;\n labelColor?: Color;\n fontFamily?: string;\n}\n\n/** Degrees of arc per drawn segment. */\nconst ARC_STEP = 4;\n/** How close to a right angle `auto` draws the square. */\nconst RIGHT_SLOP = 0.5;\n\nconst point = (radius: number, degrees: number) => {\n const turn = (degrees * Math.PI) / 180;\n return { x: radius * Math.cos(turn), y: radius * Math.sin(turn) };\n};\n\nconst state = {\n // It is only an outline.\n ...omit(PAINT, \"fill\"),\n fromAngle: Types.number(0, { unit: \"°\" }),\n toAngle: Types.number(60, { unit: \"°\" }),\n radius: Types.number(48, { min: 0, unit: \"px\" }),\n /** `auto` draws the square where the angle is a right one. */\n corner: listed([\"auto\", \"arc\", \"square\"], \"auto\", { animatable: false }),\n /** Text, a formula between dollar signs, or `°` for the angle's own size. */\n label: Types.text(\"\", { animatable: false }),\n labelSize: Types.number(24, { min: 1, unit: \"px\" }),\n labelColor: Types.color(\"#e5e7eb\"),\n fontFamily: Types.text(\"\", { animatable: false }),\n /** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */\n value: Types.number(0, { private: true }),\n};\n\ninterface AngleValues {\n readonly fromAngle: number;\n readonly toAngle: number;\n readonly radius: number;\n readonly corner: \"arc\" | \"square\" | \"auto\";\n}\n\n/**\n * The mark of an angle at the node's own position: an arc from one direction\n * to another, or the small square of a right angle, with an optional label.\n * Directions are degrees counter-clockwise from the right, so binding one to a\n * variable opens and closes the angle. A label of `°` shows the angle's size.\n */\nexport const AngleMark = component2d({\n key: \"angleMark\",\n state,\n defaults: { stroke: { weight: 3, fill: \"#e5e7eb\", align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\", value: (s) => angleOf(s) },\n load: (loader, s) => {\n if (s.label !== \"\" && s.fontFamily !== \"\") loader.font(s.fontFamily);\n loadFormulas(loader, [s.label]);\n },\n commands: {\n ...omit(PAINT_COMMANDS, \"fillTo\"),\n /** Grow or shrink the mark. */\n radiusTo: { args: [\"radius\"] },\n },\n measure: () => ({ width: 0, height: 0 }),\n bounds: (_size, s) => outlineBounds(outline(s)),\n render: (ctx, s) => {\n const data = outline(s);\n const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;\n painted(\n ctx,\n () => {\n if (shape) ctx.draw(shape().shadow(s.shadow).fill([]));\n if (s.label === \"\" || s.radius <= 0) return;\n const text = s.label === \"°\" ? `${Math.round(Math.abs(s.value) * 10) / 10}°` : s.label;\n const at = point(s.radius + s.labelSize * 0.9, (s.fromAngle + s.toAngle) / 2);\n const style = { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor };\n ctx.draw(drawLabels([{ text, at, align: \"center\" }], style));\n },\n () => {\n if (shape) strokeShape(ctx, shape, s);\n },\n );\n },\n});\n\nexport type AngleMark = NodeOf<typeof AngleMark>;\n\n/** The angle a mark marks, in degrees: positive counter-clockwise. */\nexport function angleOf(s: Pick<AngleValues, \"fromAngle\" | \"toAngle\">): number {\n return s.toAngle - s.fromAngle;\n}\n\nfunction outline({ fromAngle, toAngle, radius, corner }: AngleValues): PathCommand[] {\n const sweep = toAngle - fromAngle;\n if (radius <= 0 || sweep === 0) return [];\n const square = corner === \"square\" || (corner === \"auto\" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);\n if (square) {\n const side = radius * 0.6;\n const a = point(side, fromAngle);\n const b = point(side, toAngle);\n return [\n { type: \"M\", x: a.x, y: a.y },\n { type: \"L\", x: a.x + b.x, y: a.y + b.y },\n { type: \"L\", x: b.x, y: b.y },\n ];\n }\n const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));\n const out: PathCommand[] = [];\n for (let i = 0; i <= steps; i++) {\n const p = point(radius, fromAngle + (sweep * i) / steps);\n out.push({ type: i === 0 ? \"M\" : \"L\", x: p.x, y: p.y });\n }\n return out;\n}\n"]}