@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
@@ -0,0 +1,186 @@
1
+ import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
2
+ import { isIdentityMatrix, lerpMatrix, lineThrough, readMatrix, transformedMap, warpedMap, } from "../kit/coords.js";
3
+ import { fieldParams, parseField } from "../kit/field.js";
4
+ import { AXIS_COLOR } from "../kit/furniture.js";
5
+ import { lerpSource, readSource } from "../kit/source.js";
6
+ import { drawSystem, plotArea, systemLayout, systemOpenPlane, systemProvides, systemSize } from "../kit/system.js";
7
+ import { AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes } from "./axes2d.js";
8
+ const state = {
9
+ ...AXES,
10
+ grid: Types.boolean(true, { animatable: false }),
11
+ /** The line at every tick. */
12
+ gridStroke: Types.stroke({ weight: 1.5, fill: "#3b4658", align: "center" }),
13
+ /** The lines between ticks. */
14
+ minorStroke: Types.stroke({ weight: 1, fill: "#232b38", align: "center" }),
15
+ /** How many parts the space between two ticks is cut into; one draws no line between them. */
16
+ minorDivisions: Types.number(2, { min: 1, max: 10, step: 1 }),
17
+ /** A linear map of the plane, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */
18
+ matrix: Types.custom([1, 0, 0, 1], { resolve: readMatrix, lerp: lerpMatrix }),
19
+ /**
20
+ * Where each point of the plane is sent, two parts in x and y:
21
+ * `(x + sin(y), y + sin(x))`. Empty leaves the plane flat.
22
+ */
23
+ warp: Types.custom("", { resolve: readSource, lerp: lerpSource, kind: "fieldEquation" }),
24
+ /** Leave the plane as it was, faintly, behind one that has been transformed or warped. */
25
+ ghost: Types.boolean(true, { animatable: false }),
26
+ };
27
+ /**
28
+ * Axes over a full grid, with square units unless told otherwise: the plane
29
+ * vectors and transformations are drawn on. Its `matrix` shears, turns or
30
+ * squeezes the whole plane about its origin, and its `warp` bends it by a
31
+ * function of its own points; the grid, the axes and everything on the plane
32
+ * go with it.
33
+ */
34
+ export const NumberPlane = component2d({
35
+ key: "numberPlane",
36
+ state,
37
+ defaults: {
38
+ squareUnits: true,
39
+ stroke: { weight: 2, fill: AXIS_COLOR, align: "center" },
40
+ // A transformed plane reaches past its box, and so does what is on it: both are kept in unless told otherwise.
41
+ clip: (s) => spills(s),
42
+ },
43
+ load: (loader, s) => loadAxes(loader, s),
44
+ commands: {
45
+ ...AXES_COMMANDS,
46
+ /** Send the plane through a matrix: a shear, a turn, a squeeze, a flip. */
47
+ transformTo: { args: ["matrix"] },
48
+ /** Bend the plane, each point travelling to where the warp sends it; an empty one flattens it again. */
49
+ warpTo: { args: ["warp"] },
50
+ },
51
+ provide: (s) => systemProvides(s),
52
+ measure: (_measurer, s) => systemSize(s),
53
+ layout: (box, s, children) => systemLayout(box, s, children, planeMap),
54
+ plane: (box, s) => systemOpenPlane(box, s, planeMap),
55
+ render: (ctx, s) => {
56
+ const { flat, map } = planeMaps(plotArea(ctx.size, s.padding), s);
57
+ drawSystem(ctx, s, map, (on) => axesFurniture(on, s, (x, y) => grid(s, flat, on, x, y)));
58
+ },
59
+ });
60
+ /** The plane's map on a plot area: the flat one, sent through its matrix and its warp. */
61
+ export function planeMap(area, s) {
62
+ return planeMaps(area, s).map;
63
+ }
64
+ /** The flat plane on a plot area, and the plane as its matrix and its warp have it. */
65
+ function planeMaps(area, s) {
66
+ const flat = axesMap(area, s);
67
+ const map = isIdentityMatrix(s.matrix) ? flat : transformedMap(flat, s.matrix);
68
+ const { source, blend } = s.warp;
69
+ const to = warpOf(source);
70
+ if (!blend)
71
+ return { flat, map: to ? warpedMap(map, to, source) : map };
72
+ // Mid-warp each point is part of the way from where the old warp had it to where the new one sends it.
73
+ const from = warpOf(blend.from);
74
+ if (!from && !to)
75
+ return { flat, map };
76
+ const start = { x: 0, y: 0 };
77
+ return {
78
+ flat,
79
+ map: warpedMap(map, (x, y, out) => {
80
+ if (!(from ?? STAY)(x, y, start) || !(to ?? STAY)(x, y, out))
81
+ return false;
82
+ out.x = start.x + (out.x - start.x) * blend.t;
83
+ out.y = start.y + (out.y - start.y) * blend.t;
84
+ return true;
85
+ }, `${blend.from}>${source}@${blend.t}`),
86
+ };
87
+ }
88
+ /** Whether the plane reaches past its box: it is transformed or warped. */
89
+ function spills(s) {
90
+ if (!isIdentityMatrix(s.matrix))
91
+ return true;
92
+ const { source, blend } = s.warp;
93
+ return warpOf(source) !== null || (blend !== undefined && warpOf(blend.from) !== null);
94
+ }
95
+ /** The grid behind the axes, with the flat plane faintly behind a transformed one. */
96
+ function grid(s, flat, map, x, y) {
97
+ if (!s.grid)
98
+ return [];
99
+ const parts = [];
100
+ if (s.ghost && flat.revision !== map.revision) {
101
+ const [gx, gy] = axesOf(flat, s);
102
+ parts.push(...ruled(s, flat, gx, gy, true));
103
+ }
104
+ parts.push(...ruled(s, map, x, y, false));
105
+ return parts;
106
+ }
107
+ /** The grid of `map`: every line, or only the ones at a tick, in the fainter stroke, for a ghost. */
108
+ function ruled(s, map, x, y, ghost) {
109
+ const { start, end } = s;
110
+ const [xMin, xMax] = map.xRange;
111
+ const [yMin, yMax] = map.yRange;
112
+ const lines = (values, vertical) => {
113
+ const g = new Graphics2D();
114
+ for (const value of values) {
115
+ g.line({
116
+ points: vertical ? lineThrough(map, value, yMin, value, yMax) : lineThrough(map, xMin, value, xMax, value),
117
+ radius: 0,
118
+ start,
119
+ end,
120
+ });
121
+ }
122
+ return g;
123
+ };
124
+ const parts = [];
125
+ const minor = s.minorStroke;
126
+ if (ghost) {
127
+ if (minor.length === 0)
128
+ return parts;
129
+ if (x.marks.values.length > 0)
130
+ parts.push(lines(x.marks.values, true).stroke(minor));
131
+ if (y.marks.values.length > 0)
132
+ parts.push(lines(y.marks.values, false).stroke(minor));
133
+ return parts;
134
+ }
135
+ const divisions = Math.round(s.minorDivisions);
136
+ if (minor.length > 0 && divisions > 1) {
137
+ const between = (axis, [min, max]) => {
138
+ const { step, values } = axis.marks;
139
+ if (!(step > 0) || values.length === 0)
140
+ return [];
141
+ const out = [];
142
+ for (let base = values[0] - step; base < max; base += step) {
143
+ for (let i = 1; i < divisions; i++) {
144
+ const value = base + (step * i) / divisions;
145
+ if (value > min && value < max)
146
+ out.push(value);
147
+ }
148
+ }
149
+ return out;
150
+ };
151
+ const xs = between(x, map.xRange);
152
+ const ys = between(y, map.yRange);
153
+ if (xs.length > 0)
154
+ parts.push(lines(xs, true).stroke(minor));
155
+ if (ys.length > 0)
156
+ parts.push(lines(ys, false).stroke(minor));
157
+ }
158
+ const major = s.gridStroke;
159
+ if (major.length > 0) {
160
+ if (x.marks.values.length > 0)
161
+ parts.push(lines(x.marks.values, true).stroke(major));
162
+ if (y.marks.values.length > 0)
163
+ parts.push(lines(y.marks.values, false).stroke(major));
164
+ }
165
+ return parts;
166
+ }
167
+ const STAY = (x, y, out) => {
168
+ out.x = x;
169
+ out.y = y;
170
+ return true;
171
+ };
172
+ /** `source` as a warp, or `null` for text that is empty or not a field: the plane is then left as it is. */
173
+ function warpOf(source) {
174
+ const field = source.trim() === "" ? null : parseField(source, fieldParams(source));
175
+ if (!field || field instanceof Error)
176
+ return null;
177
+ const { x, y } = field;
178
+ return (gx, gy, out) => {
179
+ const wx = x(gx, gy);
180
+ const wy = y(gx, gy);
181
+ out.x = wx;
182
+ out.y = wy;
183
+ return Number.isFinite(wx) && Number.isFinite(wy);
184
+ };
185
+ }
186
+ //# sourceMappingURL=number-plane.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number-plane.js","sourceRoot":"","sources":["../../src/systems/number-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAcR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,UAAU,EACV,cAAc,EACd,SAAS,GAIZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OA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sourcesContent":["import {\n component2d,\n Graphics2D,\n Types,\n type Extents,\n type NodeOf,\n type Stroke,\n type StrokeResolved,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Color as _Color,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type NormalizedColor as _NormalizedColor,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n} from \"@motionscript/sdk\";\nimport {\n isIdentityMatrix,\n lerpMatrix,\n lineThrough,\n readMatrix,\n transformedMap,\n warpedMap,\n type CoordinateMap,\n type Matrix2,\n type Warp,\n} from \"../kit/coords\";\nimport { fieldParams, parseField } from \"../kit/field\";\nimport { AXIS_COLOR } from \"../kit/furniture\";\nimport { lerpSource, readSource, type PlotSource } from \"../kit/source\";\nimport { drawSystem, plotArea, systemLayout, systemOpenPlane, systemProvides, systemSize } from \"../kit/system\";\nimport { AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes, type Axes2dProps, type AxesValues, type AxisLayout } from \"./axes2d\";\n\nexport interface NumberPlaneProps extends Axes2dProps {\n grid?: boolean;\n gridStroke?: Stroke;\n minorStroke?: Stroke;\n minorDivisions?: number;\n matrix?: Matrix2 | readonly (readonly number[])[];\n warp?: string | PlotSource;\n ghost?: boolean;\n}\n\nconst state = {\n ...AXES,\n grid: Types.boolean(true, { animatable: false }),\n /** The line at every tick. */\n gridStroke: Types.stroke({ weight: 1.5, fill: \"#3b4658\", align: \"center\" }),\n /** The lines between ticks. */\n minorStroke: Types.stroke({ weight: 1, fill: \"#232b38\", align: \"center\" }),\n /** How many parts the space between two ticks is cut into; one draws no line between them. */\n minorDivisions: Types.number(2, { min: 1, max: 10, step: 1 }),\n /** A linear map of the plane, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */\n matrix: Types.custom<Matrix2 | readonly (readonly number[])[], Matrix2>([1, 0, 0, 1], { resolve: readMatrix, lerp: lerpMatrix }),\n /**\n * Where each point of the plane is sent, two parts in x and y:\n * `(x + sin(y), y + sin(x))`. Empty leaves the plane flat.\n */\n warp: Types.custom<string | PlotSource, PlotSource>(\"\", { resolve: readSource, lerp: lerpSource, kind: \"fieldEquation\" }),\n /** Leave the plane as it was, faintly, behind one that has been transformed or warped. */\n ghost: Types.boolean(true, { animatable: false }),\n};\n\ntype PlaneValues = AxesValues & {\n readonly grid: boolean;\n readonly gridStroke: StrokeResolved[];\n readonly minorStroke: StrokeResolved[];\n readonly minorDivisions: number;\n readonly matrix: Matrix2;\n readonly warp: PlotSource;\n readonly ghost: boolean;\n};\n\n/**\n * Axes over a full grid, with square units unless told otherwise: the plane\n * vectors and transformations are drawn on. Its `matrix` shears, turns or\n * squeezes the whole plane about its origin, and its `warp` bends it by a\n * function of its own points; the grid, the axes and everything on the plane\n * go with it.\n */\nexport const NumberPlane = component2d({\n key: \"numberPlane\",\n state,\n defaults: {\n squareUnits: true,\n stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\" },\n // A transformed plane reaches past its box, and so does what is on it: both are kept in unless told otherwise.\n clip: (s) => spills(s),\n },\n load: (loader, s) => loadAxes(loader, s),\n commands: {\n ...AXES_COMMANDS,\n /** Send the plane through a matrix: a shear, a turn, a squeeze, a flip. */\n transformTo: { args: [\"matrix\"] },\n /** Bend the plane, each point travelling to where the warp sends it; an empty one flattens it again. */\n warpTo: { args: [\"warp\"] },\n },\n provide: (s) => systemProvides(s),\n measure: (_measurer, s) => systemSize(s),\n layout: (box, s, children) => systemLayout(box, s, children, planeMap),\n plane: (box, s) => systemOpenPlane(box, s, planeMap),\n render: (ctx, s) => {\n const { flat, map } = planeMaps(plotArea(ctx.size, s.padding), s);\n drawSystem(ctx, s, map, (on) => axesFurniture(on, s, (x, y) => grid(s, flat, on, x, y)));\n },\n});\n\nexport type NumberPlane = NodeOf<typeof NumberPlane>;\n\n/** The plane's map on a plot area: the flat one, sent through its matrix and its warp. */\nexport function planeMap(area: Extents, s: PlaneValues): CoordinateMap {\n return planeMaps(area, s).map;\n}\n\n/** The flat plane on a plot area, and the plane as its matrix and its warp have it. */\nfunction planeMaps(area: Extents, s: PlaneValues): { flat: CoordinateMap; map: CoordinateMap } {\n const flat = axesMap(area, s);\n const map = isIdentityMatrix(s.matrix) ? flat : transformedMap(flat, s.matrix);\n const { source, blend } = s.warp;\n const to = warpOf(source);\n if (!blend) return { flat, map: to ? warpedMap(map, to, source) : map };\n // Mid-warp each point is part of the way from where the old warp had it to where the new one sends it.\n const from = warpOf(blend.from);\n if (!from && !to) return { flat, map };\n const start = { x: 0, y: 0 };\n return {\n flat,\n map: warpedMap(\n map,\n (x, y, out) => {\n if (!(from ?? STAY)(x, y, start) || !(to ?? STAY)(x, y, out)) return false;\n out.x = start.x + (out.x - start.x) * blend.t;\n out.y = start.y + (out.y - start.y) * blend.t;\n return true;\n },\n `${blend.from}>${source}@${blend.t}`,\n ),\n };\n}\n\n/** Whether the plane reaches past its box: it is transformed or warped. */\nfunction spills(s: PlaneValues): boolean {\n if (!isIdentityMatrix(s.matrix)) return true;\n const { source, blend } = s.warp;\n return warpOf(source) !== null || (blend !== undefined && warpOf(blend.from) !== null);\n}\n\n/** The grid behind the axes, with the flat plane faintly behind a transformed one. */\nfunction grid(s: PlaneValues, flat: CoordinateMap, map: CoordinateMap, x: AxisLayout, y: AxisLayout): Graphics2D[] {\n if (!s.grid) return [];\n const parts: Graphics2D[] = [];\n if (s.ghost && flat.revision !== map.revision) {\n const [gx, gy] = axesOf(flat, s);\n parts.push(...ruled(s, flat, gx, gy, true));\n }\n parts.push(...ruled(s, map, x, y, false));\n return parts;\n}\n\n/** The grid of `map`: every line, or only the ones at a tick, in the fainter stroke, for a ghost. */\nfunction ruled(s: PlaneValues, map: CoordinateMap, x: AxisLayout, y: AxisLayout, ghost: boolean): Graphics2D[] {\n const { start, end } = s;\n const [xMin, xMax] = map.xRange;\n const [yMin, yMax] = map.yRange;\n const lines = (values: readonly number[], vertical: boolean): Graphics2D => {\n const g = new Graphics2D();\n for (const value of values) {\n g.line({\n points: vertical ? lineThrough(map, value, yMin, value, yMax) : lineThrough(map, xMin, value, xMax, value),\n radius: 0,\n start,\n end,\n });\n }\n return g;\n };\n const parts: Graphics2D[] = [];\n const minor = s.minorStroke;\n if (ghost) {\n if (minor.length === 0) return parts;\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(minor));\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(minor));\n return parts;\n }\n const divisions = Math.round(s.minorDivisions);\n if (minor.length > 0 && divisions > 1) {\n const between = (axis: AxisLayout, [min, max]: readonly [number, number]): number[] => {\n const { step, values } = axis.marks;\n if (!(step > 0) || values.length === 0) return [];\n const out: number[] = [];\n for (let base = values[0] - step; base < max; base += step) {\n for (let i = 1; i < divisions; i++) {\n const value = base + (step * i) / divisions;\n if (value > min && value < max) out.push(value);\n }\n }\n return out;\n };\n const xs = between(x, map.xRange);\n const ys = between(y, map.yRange);\n if (xs.length > 0) parts.push(lines(xs, true).stroke(minor));\n if (ys.length > 0) parts.push(lines(ys, false).stroke(minor));\n }\n const major = s.gridStroke;\n if (major.length > 0) {\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(major));\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(major));\n }\n return parts;\n}\n\nconst STAY: Warp = (x, y, out) => {\n out.x = x;\n out.y = y;\n return true;\n};\n\n/** `source` as a warp, or `null` for text that is empty or not a field: the plane is then left as it is. */\nfunction warpOf(source: string): Warp | null {\n const field = source.trim() === \"\" ? null : parseField(source, fieldParams(source));\n if (!field || field instanceof Error) return null;\n const { x, y } = field;\n return (gx, gy, out) => {\n const wx = x(gx, gy);\n const wy = y(gx, gy);\n out.x = wx;\n out.y = wy;\n return Number.isFinite(wx) && Number.isFinite(wy);\n };\n}\n"]}
@@ -0,0 +1,98 @@
1
+ import { type Color, type NodeOf, type NormalizedColor, type PaintProps, type Stroke, type StrokeResolved, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved } from "@motionscript/sdk";
2
+ export interface PolarPlaneProps extends PaintProps {
3
+ radius?: number;
4
+ ringStep?: number;
5
+ spokes?: number;
6
+ angleUnit?: "degrees" | "radians";
7
+ gridStroke?: Stroke;
8
+ labels?: boolean;
9
+ labelSize?: number;
10
+ labelColor?: Color;
11
+ fontFamily?: string;
12
+ }
13
+ /**
14
+ * Rings and spokes about an origin: the plane a polar curve is read on.
15
+ * Children sit in its graph coordinates, x and y in the units its rings count,
16
+ * so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.
17
+ */
18
+ export declare const PolarPlane: import("@motionscript/sdk").Component<"polarPlane", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
19
+ /** The radius of the outermost ring, in graph units. */
20
+ radius: import("@motionscript/sdk").Type<number, number, false>;
21
+ /** The spacing of the rings; zero picks a tidy one for the plane's size. */
22
+ ringStep: import("@motionscript/sdk").Type<number, number, false>;
23
+ /** How many spokes divide the turn; zero draws none. */
24
+ spokes: import("@motionscript/sdk").Type<number, number, false>;
25
+ angleUnit: import("@motionscript/sdk").Type<"degrees" | "radians", "degrees" | "radians", false>;
26
+ /** The inner rings and the spokes. */
27
+ gridStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
28
+ /** A number at each ring, and an angle at each spoke. */
29
+ labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
30
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
31
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
32
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
33
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
34
+ stroke: import("@motionscript/sdk").Attribute<Stroke, StrokeResolved[]>;
35
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
36
+ start: import("@motionscript/sdk").Type<number, number, false>;
37
+ end: import("@motionscript/sdk").Type<number, number, false>;
38
+ }>, {
39
+ readonly rangeTo: readonly ["radius"];
40
+ readonly fillTo: readonly ["fill"];
41
+ readonly strokeTo: readonly ["stroke"];
42
+ readonly shadowTo: readonly ["shadow"];
43
+ readonly progressTo: readonly ["start", "end"];
44
+ readonly flash: {
45
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
46
+ };
47
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
48
+ /** The radius of the outermost ring, in graph units. */
49
+ radius: import("@motionscript/sdk").Type<number, number, false>;
50
+ /** The spacing of the rings; zero picks a tidy one for the plane's size. */
51
+ ringStep: import("@motionscript/sdk").Type<number, number, false>;
52
+ /** How many spokes divide the turn; zero draws none. */
53
+ spokes: import("@motionscript/sdk").Type<number, number, false>;
54
+ angleUnit: import("@motionscript/sdk").Type<"degrees" | "radians", "degrees" | "radians", false>;
55
+ /** The inner rings and the spokes. */
56
+ gridStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
57
+ /** A number at each ring, and an angle at each spoke. */
58
+ labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
59
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
60
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
61
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
62
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
63
+ stroke: import("@motionscript/sdk").Attribute<Stroke, StrokeResolved[]>;
64
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
65
+ start: import("@motionscript/sdk").Type<number, number, false>;
66
+ end: import("@motionscript/sdk").Type<number, number, false>;
67
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
68
+ /** The radius of the outermost ring, in graph units. */
69
+ radius: import("@motionscript/sdk").Type<number, number, false>;
70
+ /** The spacing of the rings; zero picks a tidy one for the plane's size. */
71
+ ringStep: import("@motionscript/sdk").Type<number, number, false>;
72
+ /** How many spokes divide the turn; zero draws none. */
73
+ spokes: import("@motionscript/sdk").Type<number, number, false>;
74
+ angleUnit: import("@motionscript/sdk").Type<"degrees" | "radians", "degrees" | "radians", false>;
75
+ /** The inner rings and the spokes. */
76
+ gridStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
77
+ /** A number at each ring, and an angle at each spoke. */
78
+ labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
79
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
80
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
81
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
82
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
83
+ stroke: import("@motionscript/sdk").Attribute<Stroke, StrokeResolved[]>;
84
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
85
+ start: import("@motionscript/sdk").Type<number, number, false>;
86
+ end: import("@motionscript/sdk").Type<number, number, false>;
87
+ }>, {
88
+ readonly rangeTo: readonly ["radius"];
89
+ readonly fillTo: readonly ["fill"];
90
+ readonly strokeTo: readonly ["stroke"];
91
+ readonly shadowTo: readonly ["shadow"];
92
+ readonly progressTo: readonly ["start", "end"];
93
+ readonly flash: {
94
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
95
+ };
96
+ }, _Node2D<_Node2DProps>>>>;
97
+ export type PolarPlane = NodeOf<typeof PolarPlane>;
98
+ //# sourceMappingURL=polar-plane.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polar-plane.d.ts","sourceRoot":"","sources":["../../src/systems/polar-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,KAAK,EAEV,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,cAAc,EAGnB,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAO3B,MAAM,WAAW,eAAgB,SAAQ,UAAU;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAyBD;;;;GAIG;AACH,eAAO,MAAM,UAAU;IAvBnB,wDAAwD;;IAExD,4EAA4E;;IAE5E,wDAAwD;;;IAGxD,sCAAsC;;IAEtC,yDAAyD;;;;;;;;;;;;;;;;;;;;IATzD,wDAAwD;;IAExD,4EAA4E;;IAE5E,wDAAwD;;;IAGxD,sCAAsC;;IAEtC,yDAAyD;;;;;;;;;;;IATzD,wDAAwD;;IAExD,4EAA4E;;IAE5E,wDAAwD;;;IAGxD,sCAAsC;;IAEtC,yDAAyD;;;;;;;;;;;;;;;;;;;2BAgC3D,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC"}
@@ -0,0 +1,139 @@
1
+ import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
2
+ import { listed, PAINT, PAINT_COMMANDS } from "../kit/component.js";
3
+ import { cartesianMap } from "../kit/coords.js";
4
+ import { AXIS_COLOR, drawLabels } from "../kit/furniture.js";
5
+ import { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from "../kit/system.js";
6
+ import { formatTick, ticksFor } from "../kit/ticks.js";
7
+ /** How much room, in label sizes, the angles written round the outer ring take from the plane. */
8
+ const LABEL_ROOM = 2.2;
9
+ const state = {
10
+ ...PAINT,
11
+ /** The radius of the outermost ring, in graph units. */
12
+ radius: Types.number(4, { min: 0.0001, step: 0.5 }),
13
+ /** The spacing of the rings; zero picks a tidy one for the plane's size. */
14
+ ringStep: Types.number(0, { min: 0 }),
15
+ /** How many spokes divide the turn; zero draws none. */
16
+ spokes: Types.number(12, { min: 0, max: 72, step: 1, animatable: false }),
17
+ angleUnit: listed(["degrees", "radians"], "degrees", { animatable: false }),
18
+ /** The inner rings and the spokes. */
19
+ gridStroke: Types.stroke({ weight: 1.25, fill: "#3b4658", align: "center" }),
20
+ /** A number at each ring, and an angle at each spoke. */
21
+ labels: Types.boolean(true, { animatable: false }),
22
+ labelSize: Types.number(16, { min: 1, unit: "px" }),
23
+ labelColor: Types.color(AXIS_COLOR),
24
+ fontFamily: Types.text("", { animatable: false }),
25
+ };
26
+ /**
27
+ * Rings and spokes about an origin: the plane a polar curve is read on.
28
+ * Children sit in its graph coordinates, x and y in the units its rings count,
29
+ * so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.
30
+ */
31
+ export const PolarPlane = component2d({
32
+ key: "polarPlane",
33
+ state,
34
+ /** The outer ring and the two lines through the origin. */
35
+ defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: "center" } },
36
+ load: (loader, s) => {
37
+ if (s.fontFamily !== "")
38
+ loader.font(s.fontFamily);
39
+ },
40
+ commands: {
41
+ ...PAINT_COMMANDS,
42
+ /** Animate how far out the plane reaches: a zoom about its origin. */
43
+ rangeTo: { args: ["radius"] },
44
+ },
45
+ provide: (s) => systemProvides(s),
46
+ measure: (_measurer, s) => systemSize(s),
47
+ layout: (box, s, children) => systemLayout(box, s, children, polarMap),
48
+ plane: (box, s) => systemOpenPlane(box, s, polarMap),
49
+ render: (ctx, s) => drawSystem(ctx, s, systemMap(ctx.size, s, polarMap), (map) => polarFurniture(map, s)),
50
+ });
51
+ function polarMap(area, s) {
52
+ const width = area.maxX - area.minX;
53
+ const height = area.maxY - area.minY;
54
+ // The outer ring fits the shorter side, less the room its angles are written in; units are square.
55
+ const reach = Math.max(1, Math.min(width, height) / 2 - (s.labels ? s.labelSize * LABEL_ROOM : 0));
56
+ const unit = reach / Math.max(s.radius, 1e-9);
57
+ return cartesianMap({
58
+ xRange: [-width / 2 / unit, width / 2 / unit],
59
+ yRange: [-height / 2 / unit, height / 2 / unit],
60
+ area,
61
+ });
62
+ }
63
+ function polarFurniture(map, s) {
64
+ const stroke = s.stroke;
65
+ const grid = s.gridStroke;
66
+ const { start, end, radius } = s;
67
+ const centre = map.toPoint(0, 0);
68
+ const reach = map.toPoint(radius, 0).x - centre.x;
69
+ if (!(reach > 0))
70
+ return [];
71
+ const at = (r, degrees) => {
72
+ const angle = (degrees * Math.PI) / 180;
73
+ return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));
74
+ };
75
+ const ring = (g, r) => {
76
+ const size = (map.toPoint(r, 0).x - centre.x) * 2;
77
+ return g.ellipse({ x: centre.x, y: centre.y, width: size, height: size, start, end });
78
+ };
79
+ const parts = [];
80
+ const marks = ticksFor([0, radius], s.ringStep, reach);
81
+ const rings = marks.values.filter((r) => r > 0 && r < radius * (1 - 1e-9));
82
+ const count = Math.round(s.spokes);
83
+ const turns = Array.from({ length: count }, (_, i) => (360 * i) / count);
84
+ if (grid.length > 0) {
85
+ const inner = new Graphics2D();
86
+ for (const r of rings)
87
+ ring(inner, r);
88
+ // The four along the axes are drawn with them.
89
+ for (const degrees of turns) {
90
+ if (degrees % 90 !== 0)
91
+ inner.line({ points: [centre, at(radius, degrees)], radius: 0, start, end });
92
+ }
93
+ if (rings.length > 0 || turns.some((degrees) => degrees % 90 !== 0))
94
+ parts.push(inner.stroke(grid));
95
+ }
96
+ if (stroke.length > 0) {
97
+ parts.push(ring(new Graphics2D(), radius)
98
+ .line({ points: [at(radius, 180), at(radius, 0)], radius: 0, start, end })
99
+ .line({ points: [at(radius, 270), at(radius, 90)], radius: 0, start, end })
100
+ .stroke(stroke));
101
+ }
102
+ if (!s.labels)
103
+ return parts;
104
+ const size = s.labelSize;
105
+ const labels = [];
106
+ for (const r of [...rings, radius]) {
107
+ const p = map.toPoint(r, 0);
108
+ labels.push({ text: formatTick(r, marks.step), at: { x: p.x - size * 0.2, y: p.y - size * 0.95 }, align: "right" });
109
+ }
110
+ for (const degrees of turns) {
111
+ const p = at(radius, degrees);
112
+ const cos = Math.cos((degrees * Math.PI) / 180);
113
+ const sin = Math.sin((degrees * Math.PI) / 180);
114
+ labels.push({
115
+ text: s.angleUnit === "degrees" ? `${formatTick(degrees, 1)}°` : radians(degrees),
116
+ at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },
117
+ align: cos > 0.3 ? "left" : cos < -0.3 ? "right" : "center",
118
+ });
119
+ }
120
+ parts.push(...drawLabels(labels, { fontSize: size, fontFamily: s.fontFamily, color: s.labelColor }));
121
+ return parts;
122
+ }
123
+ /** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */
124
+ function radians(degrees) {
125
+ if (degrees === 0)
126
+ return "0";
127
+ let numerator = Math.round(degrees);
128
+ let denominator = 180;
129
+ for (let a = numerator, b = denominator;; [a, b] = [b, a % b]) {
130
+ if (b === 0) {
131
+ numerator /= a;
132
+ denominator /= a;
133
+ break;
134
+ }
135
+ }
136
+ const top = numerator === 1 ? "π" : `${numerator}π`;
137
+ return denominator === 1 ? top : `${top}/${denominator}`;
138
+ }
139
+ //# sourceMappingURL=polar-plane.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polar-plane.js","sourceRoot":"","sources":["../../src/systems/polar-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAgBR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,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C,KAAK,CAAC,EAAE,CAAC;YACV,SAAS,IAAI,CAAC,CAAC;YACf,WAAW,IAAI,CAAC,CAAC;YACjB,MAAM;QACV,CAAC;IACL,CAAC;IACD,MAAM,GAAG,GAAG,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC;IACpD,OAAO,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAC7D,CAAC","sourcesContent":["import {\n component2d,\n Graphics2D,\n Types,\n type Color,\n type Extents,\n type NodeOf,\n type NormalizedColor,\n type PaintProps,\n type Stroke,\n type StrokeResolved,\n type Values,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n} from \"@motionscript/sdk\";\nimport { listed, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { cartesianMap, type CoordinateMap } from \"../kit/coords\";\nimport { AXIS_COLOR, drawLabels, type Label } from \"../kit/furniture\";\nimport { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from \"../kit/system\";\nimport { formatTick, ticksFor } from \"../kit/ticks\";\n\nexport interface PolarPlaneProps extends PaintProps {\n radius?: number;\n ringStep?: number;\n spokes?: number;\n angleUnit?: \"degrees\" | \"radians\";\n gridStroke?: Stroke;\n labels?: boolean;\n labelSize?: number;\n labelColor?: Color;\n fontFamily?: string;\n}\n\n/** How much room, in label sizes, the angles written round the outer ring take from the plane. */\nconst LABEL_ROOM = 2.2;\n\nconst state = {\n ...PAINT,\n /** The radius of the outermost ring, in graph units. */\n radius: Types.number(4, { min: 0.0001, step: 0.5 }),\n /** The spacing of the rings; zero picks a tidy one for the plane's size. */\n ringStep: Types.number(0, { min: 0 }),\n /** How many spokes divide the turn; zero draws none. */\n spokes: Types.number(12, { min: 0, max: 72, step: 1, animatable: false }),\n angleUnit: listed([\"degrees\", \"radians\"], \"degrees\", { animatable: false }),\n /** The inner rings and the spokes. */\n gridStroke: Types.stroke({ weight: 1.25, fill: \"#3b4658\", align: \"center\" }),\n /** A number at each ring, and an angle at each spoke. */\n labels: Types.boolean(true, { animatable: false }),\n labelSize: Types.number(16, { min: 1, unit: \"px\" }),\n labelColor: Types.color(AXIS_COLOR),\n fontFamily: Types.text(\"\", { animatable: false }),\n};\n\ntype PolarValues = Values<typeof state>;\n\n/**\n * Rings and spokes about an origin: the plane a polar curve is read on.\n * Children sit in its graph coordinates, x and y in the units its rings count,\n * so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.\n */\nexport const PolarPlane = component2d({\n key: \"polarPlane\",\n state,\n /** The outer ring and the two lines through the origin. */\n defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\" } },\n load: (loader, s) => {\n if (s.fontFamily !== \"\") loader.font(s.fontFamily);\n },\n commands: {\n ...PAINT_COMMANDS,\n /** Animate how far out the plane reaches: a zoom about its origin. */\n rangeTo: { args: [\"radius\"] },\n },\n provide: (s) => systemProvides(s),\n measure: (_measurer, s) => systemSize(s),\n layout: (box, s, children) => systemLayout(box, s, children, polarMap),\n plane: (box, s) => systemOpenPlane(box, s, polarMap),\n render: (ctx, s) => drawSystem(ctx, s, systemMap(ctx.size, s, polarMap), (map) => polarFurniture(map, s)),\n});\n\nexport type PolarPlane = NodeOf<typeof PolarPlane>;\n\nfunction polarMap(area: Extents, s: PolarValues): CoordinateMap {\n const width = area.maxX - area.minX;\n const height = area.maxY - area.minY;\n // The outer ring fits the shorter side, less the room its angles are written in; units are square.\n const reach = Math.max(1, Math.min(width, height) / 2 - (s.labels ? s.labelSize * LABEL_ROOM : 0));\n const unit = reach / Math.max(s.radius, 1e-9);\n return cartesianMap({\n xRange: [-width / 2 / unit, width / 2 / unit],\n yRange: [-height / 2 / unit, height / 2 / unit],\n area,\n });\n}\n\nfunction polarFurniture(map: CoordinateMap, s: PolarValues): Graphics2D[] {\n const stroke = s.stroke as StrokeResolved[];\n const grid = s.gridStroke as StrokeResolved[];\n const { start, end, radius } = s;\n const centre = map.toPoint(0, 0);\n const reach = map.toPoint(radius, 0).x - centre.x;\n if (!(reach > 0)) return [];\n const at = (r: number, degrees: number) => {\n const angle = (degrees * Math.PI) / 180;\n return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));\n };\n const ring = (g: Graphics2D, r: number): Graphics2D => {\n const size = (map.toPoint(r, 0).x - centre.x) * 2;\n return g.ellipse({ x: centre.x, y: centre.y, width: size, height: size, start, end });\n };\n\n const parts: Graphics2D[] = [];\n const marks = ticksFor([0, radius], s.ringStep, reach);\n const rings = marks.values.filter((r) => r > 0 && r < radius * (1 - 1e-9));\n const count = Math.round(s.spokes);\n const turns = Array.from({ length: count }, (_, i) => (360 * i) / count);\n\n if (grid.length > 0) {\n const inner = new Graphics2D();\n for (const r of rings) ring(inner, r);\n // The four along the axes are drawn with them.\n for (const degrees of turns) {\n if (degrees % 90 !== 0) inner.line({ points: [centre, at(radius, degrees)], radius: 0, start, end });\n }\n if (rings.length > 0 || turns.some((degrees) => degrees % 90 !== 0)) parts.push(inner.stroke(grid));\n }\n if (stroke.length > 0) {\n parts.push(\n ring(new Graphics2D(), radius)\n .line({ points: [at(radius, 180), at(radius, 0)], radius: 0, start, end })\n .line({ points: [at(radius, 270), at(radius, 90)], radius: 0, start, end })\n .stroke(stroke),\n );\n }\n if (!s.labels) return parts;\n\n const size = s.labelSize;\n const labels: Label[] = [];\n for (const r of [...rings, radius]) {\n const p = map.toPoint(r, 0);\n labels.push({ text: formatTick(r, marks.step), at: { x: p.x - size * 0.2, y: p.y - size * 0.95 }, align: \"right\" });\n }\n for (const degrees of turns) {\n const p = at(radius, degrees);\n const cos = Math.cos((degrees * Math.PI) / 180);\n const sin = Math.sin((degrees * Math.PI) / 180);\n labels.push({\n text: s.angleUnit === \"degrees\" ? `${formatTick(degrees, 1)}°` : radians(degrees),\n at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },\n align: cos > 0.3 ? \"left\" : cos < -0.3 ? \"right\" : \"center\",\n });\n }\n parts.push(...drawLabels(labels, { fontSize: size, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));\n return parts;\n}\n\n/** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */\nfunction radians(degrees: number): string {\n if (degrees === 0) return \"0\";\n let numerator = Math.round(degrees);\n let denominator = 180;\n for (let a = numerator, b = denominator; ; [a, b] = [b, a % b]) {\n if (b === 0) {\n numerator /= a;\n denominator /= a;\n break;\n }\n }\n const top = numerator === 1 ? \"π\" : `${numerator}π`;\n return denominator === 1 ? top : `${top}/${denominator}`;\n}\n"]}
@@ -0,0 +1,85 @@
1
+ import { PathCommand } from '@motionscript/sdk';
2
+ /**
3
+ * The asset key a node that typesets declares its loader under: the host waits
4
+ * for it before laying the node out, and a scene with no formula never loads it.
5
+ */
6
+ export declare const MATHJAX_LOADER = "math:mathjax";
7
+ /** Load MathJax, once. A host that typesets outside a scene (a tool, a test) awaits this first. */
8
+ export declare function loadMathJax(): Promise<void>;
9
+ /** Whether MathJax has loaded, so a formula can be typeset now. */
10
+ export declare function mathJaxLoaded(): boolean;
11
+ /** What a formula is before MathJax has loaded: nothing to draw, and nothing cached. */
12
+ export declare function blankLatex(): LatexPathResult;
13
+ /** MathJax is not loaded yet: what typesetting throws before {@link loadMathJax} has resolved. */
14
+ export declare class LatexNotLoaded extends Error {
15
+ constructor();
16
+ }
17
+ /**
18
+ * A formula MathJax could not typeset.
19
+ *
20
+ * MathJax does not throw on malformed TeX. It typesets an error box in place of
21
+ * the formula and tags it `data-mjx-error`, so the failure arrives as a drawing:
22
+ * nothing at all from the browser adaptor and a filled bar from the DOM-free
23
+ * one, which left a host able to tell a bad formula from a blank one only by the
24
+ * token count. {@link buildLatexPath} raises this instead, the same way under
25
+ * both adaptors. `\require` is an error too, since only the packages named above
26
+ * are loaded.
27
+ */
28
+ export declare class LatexError extends Error {
29
+ /** The formula that failed, as it was given. */
30
+ readonly latex: string;
31
+ /** MathJax's own description of what is wrong with it. */
32
+ readonly reason: string;
33
+ constructor(latex: string, reason: string);
34
+ }
35
+ /** A single rendered glyph or shape with its character key and path commands. */
36
+ export interface LatexToken {
37
+ /** Character this token represents, or a synthetic key for non-glyph shapes. */
38
+ token: string;
39
+ path: PathCommand[];
40
+ /** The source of the top-level term the token belongs to, `a^2` in `a^2 + b^2`; empty for none. */
41
+ term?: string;
42
+ }
43
+ /**
44
+ * A piece of a formula as its source wrote it: `x^2`, `\frac{d}{dx}`, a lone
45
+ * `+`. Every group the typesetter makes is one, so parts nest.
46
+ */
47
+ export interface LatexPart {
48
+ /** The part's own source. */
49
+ latex: string;
50
+ /** The tokens it draws, as a span of the formula's token list: `from` up to, not including, `to`. */
51
+ from: number;
52
+ to: number;
53
+ /** The index of the part it sits in, or -1 at the top. */
54
+ parent: number;
55
+ }
56
+ export interface LatexPathResult {
57
+ /** All tokens in render order. */
58
+ tokens: LatexToken[];
59
+ /** Every part of the formula, outermost first, in source order. */
60
+ parts: LatexPart[];
61
+ /** Flat array of all path commands (for legacy single-path rendering). */
62
+ commands: PathCommand[];
63
+ width: number;
64
+ height: number;
65
+ /**
66
+ * Bounding box over every token, in token coordinate space:
67
+ * [minX, minY, maxX, maxY]. All tokens share this frame, so passing it as
68
+ * each path's center frame keeps their relative layout (instead of each
69
+ * glyph centering on its own bbox).
70
+ */
71
+ bounds: [number, number, number, number];
72
+ }
73
+ export declare function buildLatexPath(text: string, fontSize: number): LatexPathResult;
74
+ /**
75
+ * The sources of a formula's parts, each once, in the order written: what a
76
+ * host offers to pick a part from. Empty for a formula that will not typeset.
77
+ */
78
+ export declare function latexPartNames(source: string): string[];
79
+ /**
80
+ * The token spans `selector` names in a formula, in source order: every part
81
+ * whose source it is, and every run of neighbouring parts that spell it
82
+ * together (`b^2 = c^2` in `a^2 + b^2 = c^2`). Empty when it names nothing.
83
+ */
84
+ export declare function findLatexParts(parts: readonly LatexPart[], selector: string): Array<[from: number, to: number]>;
85
+ //# sourceMappingURL=geometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../src/tex/geometry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAahD;;;GAGG;AACH,eAAO,MAAM,cAAc,iBAAiB,CAAC;AAE7C,mGAAmG;AACnG,wBAAgB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3C;AAED,mEAAmE;AACnE,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED,wFAAwF;AACxF,wBAAgB,UAAU,IAAI,eAAe,CAE5C;AAED,kGAAkG;AAClG,qBAAa,cAAe,SAAQ,KAAK;;CAKxC;AAID;;;;;;;;;;GAUG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACjC,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAM5C;AAED,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACvB,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,WAAW,EAAE,CAAC;IACpB,mGAAmG;IACnG,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACtB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,qGAAqG;IACrG,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC5B,kCAAkC;IAClC,MAAM,EAAE,UAAU,EAAE,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