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

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 (322) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +48 -0
  4. package/README.md +385 -3
  5. package/dist/annotate/angle-mark.d.ts +46 -0
  6. package/dist/annotate/angle-mark.d.ts.map +1 -0
  7. package/dist/annotate/angle-mark.js +132 -0
  8. package/dist/annotate/angle-mark.js.map +1 -0
  9. package/dist/annotate/curly-brace.d.ts +46 -0
  10. package/dist/annotate/curly-brace.d.ts.map +1 -0
  11. package/dist/annotate/curly-brace.js +114 -0
  12. package/dist/annotate/curly-brace.js.map +1 -0
  13. package/dist/annotate/emphasis-mark.d.ts +20 -0
  14. package/dist/annotate/emphasis-mark.d.ts.map +1 -0
  15. package/dist/annotate/emphasis-mark.js +81 -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-3GJB6AVO.js +2 -0
  19. package/dist/browser/chunks/chunk-3GJB6AVO.js.map +7 -0
  20. package/dist/browser/chunks/chunk-D5WHCVBC.js +2 -0
  21. package/dist/browser/chunks/chunk-D5WHCVBC.js.map +7 -0
  22. package/dist/browser/chunks/chunk-WL4KEX7Y.js +2 -0
  23. package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +7 -0
  24. package/dist/browser/chunks/mathjax-DNP3YRES.js +61 -0
  25. package/dist/browser/chunks/mathjax-DNP3YRES.js.map +7 -0
  26. package/dist/browser/index.js +2 -0
  27. package/dist/browser/index.js.map +7 -0
  28. package/dist/browser/kit.js +2 -0
  29. package/dist/browser/kit.js.map +7 -0
  30. package/dist/browser/manifest.json +30 -0
  31. package/dist/browser/tex.js +2 -0
  32. package/dist/browser/tex.js.map +7 -0
  33. package/dist/engine.d.ts +64 -0
  34. package/dist/engine.d.ts.map +1 -0
  35. package/dist/engine.js +42 -0
  36. package/dist/engine.js.map +1 -0
  37. package/dist/index.d.ts +30 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +30 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/kit/brace.d.ts +8 -0
  42. package/dist/kit/brace.d.ts.map +1 -0
  43. package/dist/kit/brace.js +36 -0
  44. package/dist/kit/brace.js.map +1 -0
  45. package/dist/kit/cache.d.ts +30 -0
  46. package/dist/kit/cache.d.ts.map +1 -0
  47. package/dist/kit/cache.js +53 -0
  48. package/dist/kit/cache.js.map +1 -0
  49. package/dist/kit/contour.d.ts +8 -0
  50. package/dist/kit/contour.d.ts.map +1 -0
  51. package/dist/kit/contour.js +93 -0
  52. package/dist/kit/contour.js.map +1 -0
  53. package/dist/kit/coords.d.ts +69 -0
  54. package/dist/kit/coords.d.ts.map +1 -0
  55. package/dist/kit/coords.js +224 -0
  56. package/dist/kit/coords.js.map +1 -0
  57. package/dist/kit/curve.d.ts +17 -0
  58. package/dist/kit/curve.d.ts.map +1 -0
  59. package/dist/kit/curve.js +22 -0
  60. package/dist/kit/curve.js.map +1 -0
  61. package/dist/kit/equation.d.ts +61 -0
  62. package/dist/kit/equation.d.ts.map +1 -0
  63. package/dist/kit/equation.js +168 -0
  64. package/dist/kit/equation.js.map +1 -0
  65. package/dist/kit/equation3d.d.ts +50 -0
  66. package/dist/kit/equation3d.d.ts.map +1 -0
  67. package/dist/kit/equation3d.js +103 -0
  68. package/dist/kit/equation3d.js.map +1 -0
  69. package/dist/kit/expression.d.ts +35 -0
  70. package/dist/kit/expression.d.ts.map +1 -0
  71. package/dist/kit/expression.js +124 -0
  72. package/dist/kit/expression.js.map +1 -0
  73. package/dist/kit/field-mark.d.ts +58 -0
  74. package/dist/kit/field-mark.d.ts.map +1 -0
  75. package/dist/kit/field-mark.js +129 -0
  76. package/dist/kit/field-mark.js.map +1 -0
  77. package/dist/kit/field.d.ts +14 -0
  78. package/dist/kit/field.d.ts.map +1 -0
  79. package/dist/kit/field.js +46 -0
  80. package/dist/kit/field.js.map +1 -0
  81. package/dist/kit/follow.d.ts +71 -0
  82. package/dist/kit/follow.d.ts.map +1 -0
  83. package/dist/kit/follow.js +159 -0
  84. package/dist/kit/follow.js.map +1 -0
  85. package/dist/kit/furniture.d.ts +30 -0
  86. package/dist/kit/furniture.d.ts.map +1 -0
  87. package/dist/kit/furniture.js +87 -0
  88. package/dist/kit/furniture.js.map +1 -0
  89. package/dist/kit/geometry.d.ts +13 -0
  90. package/dist/kit/geometry.d.ts.map +1 -0
  91. package/dist/kit/geometry.js +54 -0
  92. package/dist/kit/geometry.js.map +1 -0
  93. package/dist/kit/mark.d.ts +47 -0
  94. package/dist/kit/mark.d.ts.map +1 -0
  95. package/dist/kit/mark.js +103 -0
  96. package/dist/kit/mark.js.map +1 -0
  97. package/dist/kit/part-fills.d.ts +23 -0
  98. package/dist/kit/part-fills.d.ts.map +1 -0
  99. package/dist/kit/part-fills.js +46 -0
  100. package/dist/kit/part-fills.js.map +1 -0
  101. package/dist/kit/place.d.ts +18 -0
  102. package/dist/kit/place.d.ts.map +1 -0
  103. package/dist/kit/place.js +68 -0
  104. package/dist/kit/place.js.map +1 -0
  105. package/dist/kit/placement.d.ts +8 -0
  106. package/dist/kit/placement.d.ts.map +1 -0
  107. package/dist/kit/placement.js +8 -0
  108. package/dist/kit/placement.js.map +1 -0
  109. package/dist/kit/sampler.d.ts +17 -0
  110. package/dist/kit/sampler.d.ts.map +1 -0
  111. package/dist/kit/sampler.js +250 -0
  112. package/dist/kit/sampler.js.map +1 -0
  113. package/dist/kit/scale.d.ts +12 -0
  114. package/dist/kit/scale.d.ts.map +1 -0
  115. package/dist/kit/scale.js +37 -0
  116. package/dist/kit/scale.js.map +1 -0
  117. package/dist/kit/source.d.ts +22 -0
  118. package/dist/kit/source.d.ts.map +1 -0
  119. package/dist/kit/source.js +45 -0
  120. package/dist/kit/source.js.map +1 -0
  121. package/dist/kit/system.d.ts +33 -0
  122. package/dist/kit/system.d.ts.map +1 -0
  123. package/dist/kit/system.js +67 -0
  124. package/dist/kit/system.js.map +1 -0
  125. package/dist/kit/ticks.d.ts +19 -0
  126. package/dist/kit/ticks.d.ts.map +1 -0
  127. package/dist/kit/ticks.js +78 -0
  128. package/dist/kit/ticks.js.map +1 -0
  129. package/dist/kit/withdrawn.d.ts +9 -0
  130. package/dist/kit/withdrawn.d.ts.map +1 -0
  131. package/dist/kit/withdrawn.js +9 -0
  132. package/dist/kit/withdrawn.js.map +1 -0
  133. package/dist/marks/curve-area.d.ts +32 -0
  134. package/dist/marks/curve-area.d.ts.map +1 -0
  135. package/dist/marks/curve-area.js +82 -0
  136. package/dist/marks/curve-area.js.map +1 -0
  137. package/dist/marks/drop-lines.d.ts +22 -0
  138. package/dist/marks/drop-lines.d.ts.map +1 -0
  139. package/dist/marks/drop-lines.js +58 -0
  140. package/dist/marks/drop-lines.js.map +1 -0
  141. package/dist/marks/plot-point.d.ts +35 -0
  142. package/dist/marks/plot-point.d.ts.map +1 -0
  143. package/dist/marks/plot-point.js +97 -0
  144. package/dist/marks/plot-point.js.map +1 -0
  145. package/dist/marks/riemann-sum.d.ts +37 -0
  146. package/dist/marks/riemann-sum.d.ts.map +1 -0
  147. package/dist/marks/riemann-sum.js +91 -0
  148. package/dist/marks/riemann-sum.js.map +1 -0
  149. package/dist/marks/tangent-line.d.ts +27 -0
  150. package/dist/marks/tangent-line.d.ts.map +1 -0
  151. package/dist/marks/tangent-line.js +103 -0
  152. package/dist/marks/tangent-line.js.map +1 -0
  153. package/dist/marks/vector-arrow.d.ts +32 -0
  154. package/dist/marks/vector-arrow.d.ts.map +1 -0
  155. package/dist/marks/vector-arrow.js +87 -0
  156. package/dist/marks/vector-arrow.js.map +1 -0
  157. package/dist/nodes.d.ts +35 -0
  158. package/dist/nodes.d.ts.map +1 -0
  159. package/dist/nodes.js +63 -0
  160. package/dist/nodes.js.map +1 -0
  161. package/dist/plots/function-plot.d.ts +67 -0
  162. package/dist/plots/function-plot.d.ts.map +1 -0
  163. package/dist/plots/function-plot.js +215 -0
  164. package/dist/plots/function-plot.js.map +1 -0
  165. package/dist/plots/points-plot.d.ts +28 -0
  166. package/dist/plots/points-plot.d.ts.map +1 -0
  167. package/dist/plots/points-plot.js +99 -0
  168. package/dist/plots/points-plot.js.map +1 -0
  169. package/dist/plots/stream-lines.d.ts +35 -0
  170. package/dist/plots/stream-lines.d.ts.map +1 -0
  171. package/dist/plots/stream-lines.js +141 -0
  172. package/dist/plots/stream-lines.js.map +1 -0
  173. package/dist/plots/traced-path.d.ts +31 -0
  174. package/dist/plots/traced-path.d.ts.map +1 -0
  175. package/dist/plots/traced-path.js +56 -0
  176. package/dist/plots/traced-path.js.map +1 -0
  177. package/dist/plots/vector-field.d.ts +23 -0
  178. package/dist/plots/vector-field.d.ts.map +1 -0
  179. package/dist/plots/vector-field.js +91 -0
  180. package/dist/plots/vector-field.js.map +1 -0
  181. package/dist/structures/graph-layout.d.ts +11 -0
  182. package/dist/structures/graph-layout.d.ts.map +1 -0
  183. package/dist/structures/graph-layout.js +135 -0
  184. package/dist/structures/graph-layout.js.map +1 -0
  185. package/dist/structures/network-graph.d.ts +83 -0
  186. package/dist/structures/network-graph.d.ts.map +1 -0
  187. package/dist/structures/network-graph.js +289 -0
  188. package/dist/structures/network-graph.js.map +1 -0
  189. package/dist/structures/sample-space.d.ts +62 -0
  190. package/dist/structures/sample-space.d.ts.map +1 -0
  191. package/dist/structures/sample-space.js +199 -0
  192. package/dist/structures/sample-space.js.map +1 -0
  193. package/dist/systems/axes2d.d.ts +75 -0
  194. package/dist/systems/axes2d.d.ts.map +1 -0
  195. package/dist/systems/axes2d.js +193 -0
  196. package/dist/systems/axes2d.js.map +1 -0
  197. package/dist/systems/number-line.d.ts +49 -0
  198. package/dist/systems/number-line.d.ts.map +1 -0
  199. package/dist/systems/number-line.js +127 -0
  200. package/dist/systems/number-line.js.map +1 -0
  201. package/dist/systems/number-plane.d.ts +59 -0
  202. package/dist/systems/number-plane.d.ts.map +1 -0
  203. package/dist/systems/number-plane.js +193 -0
  204. package/dist/systems/number-plane.js.map +1 -0
  205. package/dist/systems/polar-plane.d.ts +48 -0
  206. package/dist/systems/polar-plane.d.ts.map +1 -0
  207. package/dist/systems/polar-plane.js +165 -0
  208. package/dist/systems/polar-plane.js.map +1 -0
  209. package/dist/tex/geometry.d.ts +85 -0
  210. package/dist/tex/geometry.d.ts.map +1 -0
  211. package/dist/tex/geometry.js +632 -0
  212. package/dist/tex/geometry.js.map +1 -0
  213. package/dist/tex/index.d.ts +11 -0
  214. package/dist/tex/index.d.ts.map +1 -0
  215. package/dist/tex/index.js +9 -0
  216. package/dist/tex/index.js.map +1 -0
  217. package/dist/tex/mathjax.d.ts +33 -0
  218. package/dist/tex/mathjax.d.ts.map +1 -0
  219. package/dist/tex/mathjax.js +74 -0
  220. package/dist/tex/mathjax.js.map +1 -0
  221. package/dist/tex/matrix.d.ts +31 -0
  222. package/dist/tex/matrix.d.ts.map +1 -0
  223. package/dist/tex/matrix.js +73 -0
  224. package/dist/tex/matrix.js.map +1 -0
  225. package/dist/tex/node.d.ts +215 -0
  226. package/dist/tex/node.d.ts.map +1 -0
  227. package/dist/tex/node.js +595 -0
  228. package/dist/tex/node.js.map +1 -0
  229. package/dist/tex/tween.d.ts +50 -0
  230. package/dist/tex/tween.d.ts.map +1 -0
  231. package/dist/tex/tween.js +253 -0
  232. package/dist/tex/tween.js.map +1 -0
  233. package/dist/three/axes3d.d.ts +87 -0
  234. package/dist/three/axes3d.d.ts.map +1 -0
  235. package/dist/three/axes3d.js +228 -0
  236. package/dist/three/axes3d.js.map +1 -0
  237. package/dist/three/curve-plot3d.d.ts +60 -0
  238. package/dist/three/curve-plot3d.d.ts.map +1 -0
  239. package/dist/three/curve-plot3d.js +143 -0
  240. package/dist/three/curve-plot3d.js.map +1 -0
  241. package/dist/three/label3d.d.ts +11 -0
  242. package/dist/three/label3d.d.ts.map +1 -0
  243. package/dist/three/label3d.js +40 -0
  244. package/dist/three/label3d.js.map +1 -0
  245. package/dist/three/plot-point3d.d.ts +26 -0
  246. package/dist/three/plot-point3d.d.ts.map +1 -0
  247. package/dist/three/plot-point3d.js +60 -0
  248. package/dist/three/plot-point3d.js.map +1 -0
  249. package/dist/three/space.d.ts +28 -0
  250. package/dist/three/space.d.ts.map +1 -0
  251. package/dist/three/space.js +47 -0
  252. package/dist/three/space.js.map +1 -0
  253. package/dist/three/surface-plot3d.d.ts +80 -0
  254. package/dist/three/surface-plot3d.d.ts.map +1 -0
  255. package/dist/three/surface-plot3d.js +290 -0
  256. package/dist/three/surface-plot3d.js.map +1 -0
  257. package/dist/three/vector-arrow3d.d.ts +25 -0
  258. package/dist/three/vector-arrow3d.d.ts.map +1 -0
  259. package/dist/three/vector-arrow3d.js +72 -0
  260. package/dist/three/vector-arrow3d.js.map +1 -0
  261. package/package.json +79 -3
  262. package/registry.json +251 -0
  263. package/src/annotate/angle-mark.ts +147 -0
  264. package/src/annotate/curly-brace.ts +126 -0
  265. package/src/annotate/emphasis-mark.ts +89 -0
  266. package/src/engine.ts +72 -0
  267. package/src/index.ts +29 -0
  268. package/src/kit/brace.ts +37 -0
  269. package/src/kit/cache.ts +61 -0
  270. package/src/kit/contour.ts +94 -0
  271. package/src/kit/coords.ts +278 -0
  272. package/src/kit/curve.ts +29 -0
  273. package/src/kit/equation.ts +181 -0
  274. package/src/kit/equation3d.ts +137 -0
  275. package/src/kit/expression.ts +159 -0
  276. package/src/kit/field-mark.ts +155 -0
  277. package/src/kit/field.ts +50 -0
  278. package/src/kit/follow.ts +203 -0
  279. package/src/kit/furniture.ts +108 -0
  280. package/src/kit/geometry.ts +49 -0
  281. package/src/kit/mark.ts +131 -0
  282. package/src/kit/part-fills.ts +61 -0
  283. package/src/kit/place.ts +101 -0
  284. package/src/kit/placement.ts +8 -0
  285. package/src/kit/sampler.ts +281 -0
  286. package/src/kit/scale.ts +39 -0
  287. package/src/kit/source.ts +57 -0
  288. package/src/kit/system.ts +99 -0
  289. package/src/kit/ticks.ts +85 -0
  290. package/src/kit/withdrawn.ts +8 -0
  291. package/src/marks/curve-area.ts +89 -0
  292. package/src/marks/drop-lines.ts +63 -0
  293. package/src/marks/plot-point.ts +107 -0
  294. package/src/marks/riemann-sum.ts +98 -0
  295. package/src/marks/tangent-line.ts +103 -0
  296. package/src/marks/vector-arrow.ts +98 -0
  297. package/src/nodes.ts +63 -0
  298. package/src/plots/function-plot.ts +236 -0
  299. package/src/plots/points-plot.ts +107 -0
  300. package/src/plots/stream-lines.ts +151 -0
  301. package/src/plots/traced-path.ts +52 -0
  302. package/src/plots/vector-field.ts +88 -0
  303. package/src/structures/graph-layout.ts +145 -0
  304. package/src/structures/network-graph.ts +308 -0
  305. package/src/structures/sample-space.ts +209 -0
  306. package/src/systems/axes2d.ts +217 -0
  307. package/src/systems/number-line.ts +131 -0
  308. package/src/systems/number-plane.ts +203 -0
  309. package/src/systems/polar-plane.ts +176 -0
  310. package/src/tex/geometry.ts +703 -0
  311. package/src/tex/index.ts +14 -0
  312. package/src/tex/mathjax.ts +82 -0
  313. package/src/tex/matrix.ts +75 -0
  314. package/src/tex/node.ts +641 -0
  315. package/src/tex/tween.ts +308 -0
  316. package/src/three/axes3d.ts +240 -0
  317. package/src/three/curve-plot3d.ts +147 -0
  318. package/src/three/label3d.ts +50 -0
  319. package/src/three/plot-point3d.ts +66 -0
  320. package/src/three/space.ts +67 -0
  321. package/src/three/surface-plot3d.ts +323 -0
  322. package/src/three/vector-arrow3d.ts +77 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/kit/system.ts", "../../../src/kit/place.ts", "../../../src/systems/axes2d.ts", "../../../src/kit/coords.ts", "../../../src/kit/geometry.ts", "../../../src/kit/ticks.ts", "../../../src/kit/furniture.ts", "../../../src/kit/mark.ts", "../../../src/kit/expression.ts", "../../../src/kit/equation.ts", "../../../src/kit/source.ts", "../../../src/kit/sampler.ts", "../../../src/kit/curve.ts", "../../../src/kit/follow.ts", "../../../src/kit/field.ts", "../../../src/kit/equation3d.ts", "../../../src/three/space.ts", "../../../src/three/label3d.ts", "../../../src/plots/function-plot.ts", "../../../src/kit/contour.ts", "../../../src/kit/placement.ts", "../../../src/kit/field-mark.ts", "../../../src/kit/scale.ts", "../../../src/kit/brace.ts", "../../../src/structures/graph-layout.ts"],
4
+ "sourcesContent": ["import {\r\n Clip,\r\n flowOps,\r\n Graphics2D,\r\n insetsOps,\r\n PaintNode,\r\n type BoxBounds,\r\n type ChildPlane,\r\n type Extents,\r\n type MeasureContext2D,\r\n type Node2D,\r\n type PaintProps,\r\n type RenderContext2D,\r\n type Size2D,\r\n type SizeConstraints,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport type { CoordinateMap } from \"./coords\";\r\nimport { openPlane, placeOnMap } from \"./place\";\r\n\r\nexport type { Anchored } from \"./place\";\r\n\r\nconst NO_CONTENT: Size2D = { width: 0, height: 0 };\r\nconst CENTRE: Vector2 = { x: 0, y: 0 };\r\n\r\n/**\r\n * A node whose children sit in its graph coordinates. A child's `x`/`y` are in\r\n * the system's units and the child keeps its own size, so anything can be put\r\n * on a graph: a dot, a label, an image. A mark is drawn through the\r\n * system's map instead and laid out on its ink.\r\n *\r\n * The system's `stroke` is its axis line (so `endCap` is the tip) and its `fill`\r\n * the backdrop. Ticks, grid and labels are drawing ops, never child nodes: a\r\n * document's children would otherwise share their indices with them.\r\n */\r\nexport abstract class CoordinateSystem<P extends PaintProps = PaintProps> extends PaintNode<P> {\r\n /** How graph values land on a plot area of this size. */\r\n protected abstract mapFor(area: Extents): CoordinateMap;\r\n\r\n /** What the system draws of itself, under its children. */\r\n protected abstract furniture(map: CoordinateMap): Graphics2D[];\r\n\r\n /** This system's coordinates, as last laid out. */\r\n get coordinates(): CoordinateMap {\r\n return this._map ?? (this._map = this.mapFor(this._area(this.layoutBounds)));\r\n }\r\n\r\n // A system is the size it is given: its children are placed in it, not measured into it.\r\n override measure(constraints: SizeConstraints): Partial<Size2D> {\r\n return flowOps.size(this, constraints, this.effectivePadding(), NO_CONTENT);\r\n }\r\n\r\n protected override layoutChildren(rect: BoxBounds, scope: MeasureContext2D): void {\r\n const map = this.mapFor(this._area(rect));\r\n this._map = map;\r\n const inner = insetsOps.insetBounds(rect.width, rect.height, this.effectivePadding());\r\n this._planes = placeOnMap(this.flowChildren(), map, CENTRE, inner, scope);\r\n }\r\n\r\n override _planeOf(child: Node2D | null): ChildPlane | null {\r\n return child ? (this._planes.get(child) ?? null) : openPlane(this.coordinates, CENTRE);\r\n }\r\n\r\n protected override shapeGraphics(): Graphics2D | null {\r\n const r = this.layoutBounds;\r\n return new Graphics2D().rect({ x: 0, y: 0, width: r.width, height: r.height });\r\n }\r\n\r\n protected override renderSelf(ctx: RenderContext2D): void {\r\n super.renderSelf(ctx);\r\n const map = this.coordinates;\r\n const clip = map.spills ? this.clipSelf() : null;\r\n if (clip) ctx.beginClip(clip);\r\n for (const part of this.furniture(map)) ctx.draw(part);\r\n if (clip) ctx.endClip();\r\n }\r\n\r\n // The stroke is the axis line, drawn with the furniture: painted here it would land over the children.\r\n protected override renderStroke(): void {}\r\n\r\n protected override clipSelf(): Clip | null {\r\n const { minX, minY, maxX, maxY } = this.coordinates.area;\r\n return new Clip().rect({ x: (minX + maxX) / 2, y: (minY + maxY) / 2, width: maxX - minX, height: maxY - minY });\r\n }\r\n\r\n private _map: CoordinateMap | null = null;\r\n private _planes = new WeakMap<Node2D, ChildPlane>();\r\n\r\n /** The plot area: the box less its padding, y-up from the box's centre. */\r\n private _area(rect: BoxBounds): Extents {\r\n const inner = insetsOps.insetBounds(rect.width, rect.height, this.effectivePadding());\r\n return {\r\n minX: inner.x - inner.width / 2,\r\n maxX: inner.x + inner.width / 2,\r\n minY: -inner.y - inner.height / 2,\r\n maxY: -inner.y + inner.height / 2,\r\n };\r\n }\r\n}\r\n", "import {\r\n flowOps,\r\n type BoxBounds,\r\n type ChildPlane,\r\n type Extents,\r\n type MeasureContext2D,\r\n type Node2D,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport type { CoordinateMap } from \"./coords\";\r\n\r\n/** A child that sits somewhere other than its own `x`/`y`: a point riding a curve. */\r\nexport interface Anchored {\r\n /** The graph coordinates the child is at, given its own `x`/`y`. */\r\n anchorAt(x: number, y: number): Vector2;\r\n}\r\n\r\nfunction isAnchored(node: object): node is Anchored {\r\n return typeof (node as Partial<Anchored>).anchorAt === \"function\";\r\n}\r\n\r\n/** A child drawn through a map and laid out on its ink: a mark, told apart by what it does so a copied one is too. */\r\ninterface Traced {\r\n _resolve(map: CoordinateMap, inSystem?: boolean): Extents | null;\r\n}\r\n\r\nfunction isTraced(node: object): node is Traced {\r\n return typeof (node as Partial<Traced>)._resolve === \"function\";\r\n}\r\n\r\n/**\r\n * Lay `children` out on `map`, for whichever node holds them: a coordinate\r\n * system, or a plot holding the marks that read it. A mark goes on its ink;\r\n * anything else keeps its own size and has its `x`/`y` read as graph\r\n * coordinates. `origin` is the holder's own centre in the map's pixels (y-up),\r\n * since a child's box is placed from there. Returns each child's plane.\r\n */\r\nexport function placeOnMap(\r\n children: readonly Node2D[],\r\n map: CoordinateMap,\r\n origin: Vector2,\r\n room: BoxBounds,\r\n scope: MeasureContext2D,\r\n): WeakMap<Node2D, ChildPlane> {\r\n const planes = new WeakMap<Node2D, ChildPlane>();\r\n const others: Node2D[] = [];\r\n for (const child of children) {\r\n if (!isTraced(child)) {\r\n others.push(child);\r\n continue;\r\n }\r\n const ink = child._resolve(map);\r\n const cx = ink ? (ink.minX + ink.maxX) / 2 : origin.x;\r\n const cy = ink ? (ink.minY + ink.maxY) / 2 : origin.y;\r\n child.layout(\r\n { x: cx - origin.x, y: origin.y - cy, width: ink ? ink.maxX - ink.minX : 0, height: ink ? ink.maxY - ink.minY : 0 },\r\n scope,\r\n );\r\n planes.set(child, markPlane(map, cx, cy));\r\n }\r\n if (others.length === 0) return planes;\r\n const sizes = flowOps.measure({}, others, room, scope).sizes;\r\n others.forEach((child, i) => {\r\n // Its box is centred on the map's own centre, so its offset from there is its point.\r\n child.layout({ x: -origin.x, y: origin.y, width: sizes[i].width, height: sizes[i].height }, scope);\r\n planes.set(child, pointPlane(map, child));\r\n });\r\n return planes;\r\n}\r\n\r\n/** The plane of a child that is not there yet, under a holder centred on `origin`: where a host would drop one. */\r\nexport function openPlane(map: CoordinateMap, origin: Vector2): ChildPlane {\r\n return {\r\n toOffset: (x, y) => {\r\n const at = map.toPoint(x, y);\r\n return { x: at.x - origin.x, y: at.y - origin.y };\r\n },\r\n toCoords: (x, y) => map.toCoords(x + origin.x, y + origin.y),\r\n };\r\n}\r\n\r\nfunction pointPlane(map: CoordinateMap, child: Node2D): ChildPlane {\r\n const point: Vector2 = { x: 0, y: 0 };\r\n const anchored = isAnchored(child) ? child : null;\r\n return {\r\n toOffset: (x, y) => {\r\n const at = anchored?.anchorAt(x, y);\r\n return at ? map.toPoint(at.x, at.y, point) : map.toPoint(x, y, point);\r\n },\r\n toCoords: (x, y) => map.toCoords(x, y),\r\n };\r\n}\r\n\r\n// A mark reads its own `x`/`y` as it draws, so its holder adds nothing; a drag still answers in graph units.\r\nfunction markPlane(map: CoordinateMap, cx: number, cy: number): ChildPlane {\r\n const none: Vector2 = { x: 0, y: 0 };\r\n return {\r\n toOffset: () => none,\r\n toCoords: (x, y) => map.toCoords(cx + x, cy + y),\r\n };\r\n}\r\n", "import {\r\n colorProperty,\r\n command,\r\n Graphics2D,\r\n node,\r\n property,\r\n strokeProperty,\r\n type AssetScope,\r\n type Color,\r\n type Command,\r\n type CommandArgs,\r\n type Extents,\r\n type NodeConfig,\r\n type NormalizedColor,\r\n type PaintProps,\r\n type Stroke,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport { cartesianMap, lineThrough, resolveInterval, type AxisScaling, type CoordinateMap, type Interval } from \"../kit/coords\";\r\nimport { clamp, stated } from \"../kit/geometry\";\r\nimport { CoordinateSystem } from \"../kit/system\";\r\nimport { formatTick, ticksFor, type Ticks } from \"../kit/ticks\";\r\nimport { along, AXIS_COLOR, declareFormulas, drawLabels, drawn, type Label, lerpInterval, readInterval, withoutTips } from \"../kit/furniture\";\r\n\r\nexport interface Axes2dProps extends PaintProps {\r\n xRange?: Interval;\r\n yRange?: Interval;\r\n xStep?: number;\r\n yStep?: number;\r\n xScaling?: AxisScaling;\r\n yScaling?: AxisScaling;\r\n squareUnits?: boolean;\r\n ticks?: boolean;\r\n tickSize?: number;\r\n labels?: boolean;\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n xLabel?: string;\r\n yLabel?: string;\r\n}\r\n\r\n/** One axis, as its furniture is drawn: its line's ends and what is marked along it. */\r\ninterface AxisLayout {\r\n from: Vector2;\r\n to: Vector2;\r\n /** The pixel points that draw its line: its two ends, or more where the system's map bends it. */\r\n line: Vector2[];\r\n marks: Ticks;\r\n /** The value on this axis the other one crosses at, which is left unmarked. */\r\n crossing: number;\r\n /** A mark's pixel point. */\r\n at(value: number): Vector2;\r\n}\r\n\r\n/**\r\n * An x and a y axis, crossing at the origin while it is in range and at the\r\n * nearest edge otherwise. Children sit in its graph coordinates.\r\n */\r\n@node({\r\n key: \"axes2d\",\r\n parentKey: \"node\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"fixed\", defaultHeightMode: \"fixed\", acceptsChildren: true },\r\n seed: { width: 800, height: 500, padding: 32 },\r\n})\r\nexport class Axes2d<P extends Axes2dProps = Axes2dProps> extends CoordinateSystem<P> {\r\n @property({ default: [-5, 5], mapper: readInterval, tween: lerpInterval })\r\n declare xRange: Interval;\r\n @property({ default: [-3, 3], mapper: readInterval, tween: lerpInterval })\r\n declare yRange: Interval;\r\n\r\n /** The spacing of each axis's ticks; zero picks a tidy one for the axis's length. */\r\n @property({ default: 0, min: 0 }) declare xStep: number;\r\n @property({ default: 0, min: 0 }) declare yStep: number;\r\n @property({ default: \"linear\", options: [\"linear\", \"log\"], animatable: false }) declare xScaling: AxisScaling;\r\n @property({ default: \"linear\", options: [\"linear\", \"log\"], animatable: false }) declare yScaling: AxisScaling;\r\n /** Give a y unit the length of an x unit: `yRange` keeps its centre and takes the span that fits. */\r\n @property({ default: false, animatable: false }) declare squareUnits: boolean;\r\n\r\n @property({ default: true, animatable: false }) declare ticks: boolean;\r\n @property({ default: 10, min: 0, unit: \"px\" }) declare tickSize: number;\r\n @property({ default: true, animatable: false }) declare labels: boolean;\r\n @property({ default: 18, min: 1, unit: \"px\" }) declare labelSize: number;\r\n @colorProperty({ default: AXIS_COLOR }) declare labelColor: Color;\r\n @property({ default: \"\", animatable: false }) declare fontFamily: string;\r\n /** A title at the positive end of each axis. */\r\n @property({ default: \"\", animatable: false }) declare xLabel: string;\r\n @property({ default: \"\", animatable: false }) declare yLabel: string;\r\n\r\n @strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: \"center\", endCap: \"triangle\", capScale: 5 } })\r\n declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<Axes2d<P>, P>) {\r\n super((props ?? {}) as NodeConfig<Axes2d<P>, P>);\r\n }\r\n\r\n /** Animate the window of values the axes show: a pan when a range's ends move alike, a zoom when they do not. */\r\n @command({ args: [\"xRange\", \"yRange\"] })\r\n rangeTo(args: CommandArgs<{ xRange?: Interval; yRange?: Interval }> & { duration: number }): Command<P> {\r\n return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets);\r\n if (this.fontFamily !== \"\") assets.font(this.fontFamily);\r\n declareFormulas(assets, [this.xLabel, this.yLabel]);\r\n }\r\n\r\n protected mapFor(area: Extents): CoordinateMap {\r\n const xRange = resolveInterval(this.xRange, this.xScaling);\r\n let yRange = resolveInterval(this.yRange, this.yScaling);\r\n const width = area.maxX - area.minX;\r\n if (this.squareUnits && this.xScaling === \"linear\" && this.yScaling === \"linear\" && width > 0) {\r\n const span = ((xRange[1] - xRange[0]) * (area.maxY - area.minY)) / width;\r\n const centre = (yRange[0] + yRange[1]) / 2;\r\n if (span > 0) yRange = [centre - span / 2, centre + span / 2];\r\n }\r\n return cartesianMap({ xRange, yRange, area, xScaling: this.xScaling, yScaling: this.yScaling });\r\n }\r\n\r\n protected furniture(map: CoordinateMap): Graphics2D[] {\r\n const stroke = this.stroke as StrokeResolved[];\r\n const { start, end } = this;\r\n const [x, y] = this.axes(map);\r\n const parts: Graphics2D[] = [...this.backdrop(map, x, y)];\r\n if (stroke.length === 0 && !this.labels) return parts;\r\n\r\n if (stroke.length > 0) {\r\n parts.push(\r\n new Graphics2D()\r\n .line({ points: x.line, radius: 0, start, end })\r\n .line({ points: y.line, radius: 0, start, end })\r\n .stroke(stroke),\r\n );\r\n }\r\n\r\n const half = this.tickSize / 2;\r\n const gap = half + this.labelSize * 0.35;\r\n const tickMarks = new Graphics2D();\r\n const labels: Label[] = [];\r\n let ticked = false;\r\n const mark = (axis: AxisLayout, horizontal: boolean): void => {\r\n for (const value of axis.marks.values) {\r\n if (Math.abs(value - axis.crossing) < 1e-9 * Math.max(1, Math.abs(value))) continue;\r\n const at = axis.at(value);\r\n if (!drawn(along(at, axis.from, axis.to), start, end)) continue;\r\n if (this.ticks && half > 0) {\r\n tickMarks.line({\r\n points: horizontal\r\n ? [{ x: at.x, y: at.y - half }, { x: at.x, y: at.y + half }]\r\n : [{ x: at.x - half, y: at.y }, { x: at.x + half, y: at.y }],\r\n radius: 0,\r\n });\r\n ticked = true;\r\n }\r\n if (!this.labels) continue;\r\n labels.push(\r\n horizontal\r\n ? { text: formatTick(value, axis.marks.step), at: { x: at.x, y: at.y - gap - this.labelSize / 2 }, align: \"center\" }\r\n : { text: formatTick(value, axis.marks.step), at: { x: at.x - gap, y: at.y }, align: \"right\" },\r\n );\r\n }\r\n };\r\n mark(x, true);\r\n mark(y, false);\r\n if (ticked && stroke.length > 0) parts.push(tickMarks.stroke(withoutTips(stroke)));\r\n\r\n if (this.xLabel !== \"\" && end >= 1) {\r\n labels.push({ text: this.xLabel, at: { x: x.to.x, y: x.to.y + gap + this.labelSize / 2 }, align: \"right\" });\r\n }\r\n if (this.yLabel !== \"\" && end >= 1) {\r\n labels.push({ text: this.yLabel, at: { x: y.to.x + gap, y: y.to.y - this.labelSize / 2 }, align: \"left\" });\r\n }\r\n parts.push(...drawLabels(labels, { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor }));\r\n return parts;\r\n }\r\n\r\n /** What is drawn behind the axes: nothing here, a grid on a number plane. */\r\n protected backdrop(_map: CoordinateMap, _x: AxisLayout, _y: AxisLayout): Graphics2D[] {\r\n return [];\r\n }\r\n\r\n /** The two axes as laid out: where each runs, what it marks, and where the other crosses it. */\r\n protected axes(map: CoordinateMap): [AxisLayout, AxisLayout] {\r\n const [xMin, xMax] = map.xRange;\r\n const [yMin, yMax] = map.yRange;\r\n // An axis sits on the other's zero, or on its near edge when zero is out of range or it is logarithmic.\r\n const crossX = this.xScaling === \"log\" ? xMin : clamp(0, xMin, xMax);\r\n const crossY = this.yScaling === \"log\" ? yMin : clamp(0, yMin, yMax);\r\n const xFrom = map.toPoint(xMin, crossY);\r\n const xTo = map.toPoint(xMax, crossY);\r\n const yFrom = map.toPoint(crossX, yMin);\r\n const yTo = map.toPoint(crossX, yMax);\r\n return [\r\n {\r\n from: xFrom,\r\n to: xTo,\r\n line: lineThrough(map, xMin, crossY, xMax, crossY),\r\n marks: ticksFor(map.xRange, this.xStep, Math.hypot(xTo.x - xFrom.x, xTo.y - xFrom.y), this.xScaling),\r\n crossing: crossX,\r\n at: (value) => map.toPoint(value, crossY),\r\n },\r\n {\r\n from: yFrom,\r\n to: yTo,\r\n line: lineThrough(map, crossX, yMin, crossX, yMax),\r\n marks: ticksFor(map.yRange, this.yStep, Math.hypot(yTo.x - yFrom.x, yTo.y - yFrom.y), this.yScaling),\r\n crossing: crossY,\r\n at: (value) => map.toPoint(crossX, value),\r\n },\r\n ];\r\n }\r\n}\r\n\r\nexport type { AxisLayout };\r\n", "import type { Extents, Vector2 } from \"@motionscript/sdk\";\r\n\r\n/** A closed span of graph values, low to high. */\r\nexport type Interval = readonly [number, number];\r\n\r\nexport type AxisScaling = \"linear\" | \"log\";\r\n\r\n/**\r\n * How a coordinate system's graph values land on its pixels. Pixels are y-up\r\n * from the centre of the system's own box, which is the frame a `Graphics2D` op\r\n * is written in.\r\n */\r\nexport interface CoordinateMap {\r\n /** Graph to pixels. Writes into `out` when given, so a sampler allocates nothing. */\r\n toPoint(x: number, y: number, out?: Vector2): Vector2;\r\n toCoords(x: number, y: number, out?: Vector2): Vector2;\r\n /** The plot area. */\r\n readonly area: Extents;\r\n readonly xRange: Interval;\r\n readonly yRange: Interval;\r\n /** Equal for two maps that place every point alike: what a geometry cache keys on. */\r\n readonly revision: string;\r\n /** Set where a straight run of graph values is not a straight run of pixels, so a line through the map is sampled. */\r\n readonly curved?: boolean;\r\n /** Set where what is ruled over the ranges can leave the plot area, so the system keeps it in. */\r\n readonly spills?: boolean;\r\n}\r\n\r\n/** One axis: a graph value to a pixel and back. */\r\nexport interface AxisScale {\r\n to(value: number): number;\r\n from(pixel: number): number;\r\n}\r\n\r\n/** `range`, made usable: finite, ordered, non-empty, and positive on a log axis. */\r\nexport function resolveInterval(range: Interval | undefined, scaling: AxisScaling = \"linear\"): Interval {\r\n let [min, max] = range ?? [0, 1];\r\n if (!Number.isFinite(min) || !Number.isFinite(max)) [min, max] = [0, 1];\r\n if (min > max) [min, max] = [max, min];\r\n if (scaling === \"log\") {\r\n if (!(max > 0)) max = 10;\r\n if (!(min > 0)) min = max / 1000;\r\n }\r\n return max > min ? [min, max] : [min, min + 1];\r\n}\r\n\r\n/** `range` spread over the pixels from `lo` to `hi`. */\r\nexport function axisScale(range: Interval, lo: number, hi: number, scaling: AxisScaling = \"linear\"): AxisScale {\r\n const [min, max] = range;\r\n if (scaling === \"log\") {\r\n const from = Math.log10(min);\r\n const k = (hi - lo) / (Math.log10(max) - from);\r\n return { to: (v) => lo + (Math.log10(v) - from) * k, from: (p) => 10 ** (from + (p - lo) / k) };\r\n }\r\n const k = (hi - lo) / (max - min);\r\n return { to: (v) => lo + (v - min) * k, from: (p) => min + (p - lo) / k };\r\n}\r\n\r\nexport interface CartesianOptions {\r\n xRange: Interval;\r\n yRange: Interval;\r\n area: Extents;\r\n xScaling?: AxisScaling;\r\n yScaling?: AxisScaling;\r\n}\r\n\r\n/** Two independent axes at right angles: what a number line, axes and a number plane share. */\r\nexport function cartesianMap({ xRange, yRange, area, xScaling = \"linear\", yScaling = \"linear\" }: CartesianOptions): CoordinateMap {\r\n const x = axisScale(xRange, area.minX, area.maxX, xScaling);\r\n const y = axisScale(yRange, area.minY, area.maxY, yScaling);\r\n return {\r\n toPoint: (gx, gy, out = { x: 0, y: 0 }) => {\r\n out.x = x.to(gx);\r\n out.y = y.to(gy);\r\n return out;\r\n },\r\n toCoords: (px, py, out = { x: 0, y: 0 }) => {\r\n out.x = x.from(px);\r\n out.y = y.from(py);\r\n return out;\r\n },\r\n area,\r\n xRange,\r\n yRange,\r\n revision: [xRange, yRange, area.minX, area.minY, area.maxX, area.maxY, xScaling, yScaling].join(\"|\"),\r\n };\r\n}\r\n\r\nconst UNBOUNDED: Extents = { minX: -Infinity, minY: -Infinity, maxX: Infinity, maxY: Infinity };\r\n\r\n/** One graph unit is one pixel: what a mark outside any system is drawn through. */\r\nexport const PIXEL_MAP: CoordinateMap = {\r\n toPoint: (x, y, out = { x: 0, y: 0 }) => {\r\n out.x = x;\r\n out.y = y;\r\n return out;\r\n },\r\n toCoords: (x, y, out = { x: 0, y: 0 }) => {\r\n out.x = x;\r\n out.y = y;\r\n return out;\r\n },\r\n area: UNBOUNDED,\r\n xRange: [-Infinity, Infinity],\r\n yRange: [-Infinity, Infinity],\r\n revision: \"pixels\",\r\n};\r\n\r\n/** A 2 × 2 matrix, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */\r\nexport type Matrix2 = readonly [number, number, number, number];\r\n\r\nexport const IDENTITY_MATRIX: Matrix2 = [1, 0, 0, 1];\r\n\r\n/** A matrix from its rows, or flat; anything else is the identity. */\r\nexport function readMatrix(value: unknown, previous: Matrix2 = IDENTITY_MATRIX): Matrix2 {\r\n const flat = Array.isArray(value) ? value.flat() : [];\r\n if (flat.length !== 4 || flat.some((entry) => typeof entry !== \"number\" || !Number.isFinite(entry))) return previous;\r\n return [flat[0], flat[1], flat[2], flat[3]];\r\n}\r\n\r\nexport function lerpMatrix(from: Matrix2, to: Matrix2, t: number): Matrix2 {\r\n return [0, 1, 2, 3].map((i) => from[i] + (to[i] - from[i]) * t) as unknown as Matrix2;\r\n}\r\n\r\nexport function isIdentityMatrix([a, b, c, d]: Matrix2): boolean {\r\n return a === 1 && b === 0 && c === 0 && d === 1;\r\n}\r\n\r\n/**\r\n * How far a transformed plane reaches, in half-widths of its own ranges about\r\n * their middle. Finite on purpose: a plane squeezed towards a line shows the\r\n * pre-image of its box growing as 1/det, and ruling all of it packs the box\r\n * with lines, a solid wash just before the plane goes flat.\r\n */\r\nconst REACH = 4;\r\n\r\nfunction reach([min, max]: Interval): Interval {\r\n const middle = (min + max) / 2;\r\n const half = ((max - min) / 2) * REACH;\r\n return [middle - half, middle + half];\r\n}\r\n\r\n/**\r\n * `base` with every graph point sent through `matrix` first: a plane sheared,\r\n * turned or squeezed about its origin. Its ranges are what the plot area then\r\n * shows, up to {@link REACH}, so a grid ruled over them fills the box under a\r\n * turn, a shear or a fourfold shrink, and folds into a band as it goes flat.\r\n */\r\nexport function transformedMap(base: CoordinateMap, matrix: Matrix2): CoordinateMap {\r\n const [a, b, c, d] = matrix;\r\n const det = a * d - b * c;\r\n // A plane squeezed onto a line has no way back: a point is read as the untransformed plane has it.\r\n const flat = Math.abs(det) < 1e-9;\r\n const back = (u: number, v: number, out: Vector2): Vector2 => {\r\n if (flat) {\r\n out.x = u;\r\n out.y = v;\r\n } else {\r\n out.x = (d * u - b * v) / det;\r\n out.y = (a * v - c * u) / det;\r\n }\r\n return out;\r\n };\r\n const xReach = reach(base.xRange);\r\n const yReach = reach(base.yRange);\r\n let xRange = xReach;\r\n let yRange = yReach;\r\n if (!flat) {\r\n const corner: Vector2 = { x: 0, y: 0 };\r\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\r\n for (const u of base.xRange) {\r\n for (const v of base.yRange) {\r\n back(u, v, corner);\r\n minX = Math.min(minX, corner.x);\r\n maxX = Math.max(maxX, corner.x);\r\n minY = Math.min(minY, corner.y);\r\n maxY = Math.max(maxY, corner.y);\r\n }\r\n }\r\n xRange = [Math.max(minX, xReach[0]), Math.min(maxX, xReach[1])];\r\n yRange = [Math.max(minY, yReach[0]), Math.min(maxY, yReach[1])];\r\n }\r\n return {\r\n toPoint: (x, y, out = { x: 0, y: 0 }) => base.toPoint(a * x + b * y, c * x + d * y, out),\r\n toCoords: (px, py, out = { x: 0, y: 0 }) => {\r\n base.toCoords(px, py, out);\r\n return back(out.x, out.y, out);\r\n },\r\n area: base.area,\r\n xRange,\r\n yRange,\r\n revision: `${base.revision}|m${matrix.join(\",\")}`,\r\n spills: true,\r\n };\r\n}\r\n\r\n/** Where a warp sends a graph point, written into `out`; `false` where it has no value. */\r\nexport type Warp = (x: number, y: number, out: Vector2) => boolean;\r\n\r\n/**\r\n * `base` with every graph point sent to where `warp` sends it: a plane bent by\r\n * a function of its own points. `key` names the warp for the revision, since a\r\n * function has no text of its own.\r\n */\r\nexport function warpedMap(base: CoordinateMap, warp: Warp, key: string): CoordinateMap {\r\n const bend = (x: number, y: number, out: Vector2): Vector2 => {\r\n // A point the warp has no value at stays where it is, so a pole does not tear the grid.\r\n if (!warp(x, y, out)) {\r\n out.x = x;\r\n out.y = y;\r\n }\r\n return out;\r\n };\r\n const at: Vector2 = { x: 0, y: 0 };\r\n const dx: Vector2 = { x: 0, y: 0 };\r\n const dy: Vector2 = { x: 0, y: 0 };\r\n const H = 1e-4;\r\n return {\r\n toPoint: (x, y, out = { x: 0, y: 0 }) => {\r\n bend(x, y, out);\r\n return base.toPoint(out.x, out.y, out);\r\n },\r\n // No closed form: a few Newton steps from where the unbent plane has the point.\r\n toCoords: (px, py, out = { x: 0, y: 0 }) => {\r\n const target = base.toCoords(px, py);\r\n let gx = target.x;\r\n let gy = target.y;\r\n for (let i = 0; i < 8; i++) {\r\n bend(gx, gy, at);\r\n const ex = at.x - target.x;\r\n const ey = at.y - target.y;\r\n if (Math.abs(ex) + Math.abs(ey) < 1e-9) break;\r\n bend(gx + H, gy, dx);\r\n bend(gx, gy + H, dy);\r\n const j00 = (dx.x - at.x) / H;\r\n const j10 = (dx.y - at.y) / H;\r\n const j01 = (dy.x - at.x) / H;\r\n const j11 = (dy.y - at.y) / H;\r\n const det = j00 * j11 - j01 * j10;\r\n if (!(Math.abs(det) > 1e-12)) break;\r\n gx -= (j11 * ex - j01 * ey) / det;\r\n gy -= (j00 * ey - j10 * ex) / det;\r\n }\r\n out.x = Number.isFinite(gx) ? gx : target.x;\r\n out.y = Number.isFinite(gy) ? gy : target.y;\r\n return out;\r\n },\r\n area: base.area,\r\n // A bent plane pulls its edges in somewhere: it is ruled a little past them so the box stays full.\r\n xRange: widened(base.xRange),\r\n yRange: widened(base.yRange),\r\n revision: `${base.revision}|w${key}`,\r\n curved: true,\r\n spills: true,\r\n };\r\n}\r\n\r\n/** How much further than its range, as a share of it, a warped plane is ruled each way. */\r\nconst WARP_MARGIN = 0.3;\r\n\r\nfunction widened([min, max]: Interval): Interval {\r\n const margin = (max - min) * WARP_MARGIN;\r\n return Number.isFinite(margin) ? [min - margin, max + margin] : [min, max];\r\n}\r\n\r\n/** How many pieces a line through a curved map is drawn in. */\r\nconst CURVED_STEPS = 48;\r\n\r\n/** The pixel points that draw the straight run of graph values from one point to another. */\r\nexport function lineThrough(map: CoordinateMap, x0: number, y0: number, x1: number, y1: number): Vector2[] {\r\n if (!map.curved) return [map.toPoint(x0, y0), map.toPoint(x1, y1)];\r\n const run: Vector2[] = [];\r\n for (let i = 0; i <= CURVED_STEPS; i++) {\r\n const t = i / CURVED_STEPS;\r\n run.push(map.toPoint(x0 + (x1 - x0) * t, y0 + (y1 - y0) * t));\r\n }\r\n return run;\r\n}\r\n", "import type { Extents, PathCommand, Vector2 } from \"@motionscript/sdk\";\r\n\r\n/**\r\n * Runs of pixel points as path commands. Commands are y-up like every other\r\n * `Graphics2D` op (only an SVG `d` string is y-down), so nothing is flipped here.\r\n */\r\nexport function runsToPath(runs: readonly (readonly Vector2[])[], closed = false): PathCommand[] {\r\n const out: PathCommand[] = [];\r\n for (const run of runs) {\r\n if (run.length < 2) continue;\r\n out.push({ type: \"M\", x: run[0].x, y: run[0].y });\r\n for (let i = 1; i < run.length; i++) out.push({ type: \"L\", x: run[i].x, y: run[i].y });\r\n if (closed) out.push({ type: \"Z\" });\r\n }\r\n return out;\r\n}\r\n\r\nexport function boundsOfRuns(runs: readonly (readonly Vector2[])[]): Extents | null {\r\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\r\n for (const run of runs) {\r\n if (run.length < 2) continue;\r\n for (const p of run) {\r\n if (p.x < minX) minX = p.x;\r\n if (p.x > maxX) maxX = p.x;\r\n if (p.y < minY) minY = p.y;\r\n if (p.y > maxY) maxY = p.y;\r\n }\r\n }\r\n return minX <= maxX ? { minX, minY, maxX, maxY } : null;\r\n}\r\n\r\n/** `area` grown by `margin` on every side. */\r\nexport function inflate(area: Extents, margin: number): Extents {\r\n return { minX: area.minX - margin, minY: area.minY - margin, maxX: area.maxX + margin, maxY: area.maxY + margin };\r\n}\r\n\r\nexport function clamp(value: number, min: number, max: number): number {\r\n return value < min ? min : value > max ? max : value;\r\n}\r\n\r\n/** `data` without the arguments a command was not given, which arrive as `undefined` and are not destinations. */\r\nexport function stated<T extends object>(data: T | undefined): Partial<T> {\r\n const out: Partial<T> = {};\r\n if (!data) return out;\r\n for (const key of Object.keys(data) as (keyof T)[]) {\r\n if (data[key] !== undefined) out[key] = data[key];\r\n }\r\n return out;\r\n}\r\n", "import { niceStep } from \"@motionscript/sdk/component\";\r\nimport type { AxisScaling, Interval } from \"./coords\";\r\n\r\n/** Where an axis is marked, and the spacing its labels are rounded to. */\r\nexport interface Ticks {\r\n values: number[];\r\n step: number;\r\n}\r\n\r\n/** Past this an axis is not marked at all, rather than drawn as a solid bar of ticks. */\r\nconst MAX_TICKS = 200;\r\n\r\n/** How far apart, in pixels, marks sit when the axis picks its own step. */\r\nconst AUTO_SPACING = 64;\r\n\r\n/**\r\n * The marks along `range`, drawn over `length` pixels. A `step` of zero lets the\r\n * axis choose a tidy one (1, 2 or 5 times a power of ten) for its size; a log\r\n * axis is marked at the powers of ten whatever the step.\r\n */\r\nexport function ticksFor(range: Interval, step: number, length: number, scaling: AxisScaling = \"linear\"): Ticks {\r\n const [min, max] = range;\r\n if (scaling === \"log\") return decades(min, max);\r\n const span = max - min;\r\n if (!(span > 0)) return { values: [], step: 1 };\r\n const chosen = step > 0 ? step : niceStep((AUTO_SPACING / Math.max(1, length)) * span);\r\n return { values: multiplesWithin(min, max, chosen), step: chosen };\r\n}\r\n\r\nfunction decades(min: number, max: number): Ticks {\r\n const values: number[] = [];\r\n for (let k = Math.ceil(Math.log10(min) - 1e-9); k <= Math.floor(Math.log10(max) + 1e-9) && values.length < MAX_TICKS; k++) {\r\n values.push(10 ** k);\r\n }\r\n return { values, step: 0 };\r\n}\r\n\r\nfunction multiplesWithin(min: number, max: number, step: number): number[] {\r\n const first = Math.ceil(min / step - 1e-9);\r\n const last = Math.floor(max / step + 1e-9);\r\n const count = last - first + 1;\r\n if (!Number.isFinite(count) || count <= 0 || count > MAX_TICKS) return [];\r\n const out = new Array<number>(count);\r\n // Multiplied rather than accumulated, so the tenth tick of 0.1 is 1 and not 0.9999999999999999.\r\n for (let i = 0; i < count; i++) out[i] = (first + i) * step;\r\n return out;\r\n}\r\n\r\nfunction decadeOf(value: number): number {\r\n return Math.floor(Math.log10(value) + 1e-12);\r\n}\r\n\r\n/**\r\n * `value` as a tick label, with as many decimals as `step` needs and no more:\r\n * 0.30000000000000004 on a 0.1 ladder is `0.3`. A `step` of zero (a log axis)\r\n * prints the value as it is.\r\n */\r\nexport function formatTick(value: number, step: number): string {\r\n if (value === 0) return \"0\";\r\n if (!Number.isFinite(value)) return \"\";\r\n if (!(step > 0)) {\r\n const decade = decadeOf(Math.abs(value));\r\n return decade >= 6 || decade <= -5 ? trimExponent(value.toExponential(0)) : String(Number(value.toPrecision(12)));\r\n }\r\n const decade = decadeOf(Math.abs(value));\r\n const digits = Math.max(1, decade - decadeOf(step) + 1);\r\n if ((decade >= 6 || decade <= -5) && digits <= 6) return trimExponent(value.toExponential(digits - 1));\r\n const decimals = decimalsOf(step);\r\n const text = value.toFixed(decimals);\r\n return decimals > 0 ? text.replace(/\\.?0+$/, \"\") : text;\r\n}\r\n\r\n/** The decimal places it takes to write `step` out: 1 for 0.5, 2 for 0.25. */\r\nfunction decimalsOf(step: number): number {\r\n for (let d = 0; d < 12; d++) {\r\n const scaled = step * 10 ** d;\r\n if (Math.abs(scaled - Math.round(scaled)) < 1e-9 * Math.max(1, scaled)) return d;\r\n }\r\n return 12;\r\n}\r\n\r\nfunction trimExponent(text: string): string {\r\n const [mantissa, exponent] = text.split(\"e\");\r\n return `${mantissa.replace(/\\.?0+$/, \"\")}e${Number(exponent)}`;\r\n}\r\n", "import { Fills, Graphics2D, toPathString, type AssetScope, type Color, type StrokeResolved, type Vector2 } from \"@motionscript/sdk\";\r\nimport { buildLatexPath, LatexNotLoaded, loadMathJax, MATHJAX_LOADER } from \"../tex/geometry\";\r\nimport type { Interval } from \"./coords\";\r\n\r\n/** Shared drawing for the systems' own furniture: axis lines, tick marks and their numbers. */\r\n\r\n/** What a system draws its axes and numbers in, and a plot its curve, until told otherwise. */\r\nexport const AXIS_COLOR = \"#9ca3af\";\r\nexport const PLOT_COLOR = \"#58a6ff\";\r\n\r\n/** A stroke without end markers: an axis wears a tip, its ticks do not. */\r\nexport function withoutTips(stroke: StrokeResolved[]): StrokeResolved[] {\r\n return stroke.map((layer) => ({ ...layer, startCap: undefined, endCap: undefined }));\r\n}\r\n\r\nexport interface LabelStyle {\r\n fontSize: number;\r\n fontFamily: string;\r\n color: Color;\r\n}\r\n\r\nexport interface Label {\r\n text: string;\r\n /** Where the label's box is anchored, in pixels. */\r\n at: Vector2;\r\n align: \"left\" | \"center\" | \"right\";\r\n}\r\n\r\n/** How wide a label's box is, in ems: room for a long number, so alignment is by the box's edge. */\r\nconst LABEL_BOX_EM = 8;\r\n\r\n/** A label written between dollar signs is a formula: `$\\\\frac{\\\\pi}{2}$`. */\r\nconst FORMULA = /^\\$([\\s\\S]+)\\$$/;\r\n\r\n/** Ask the host for MathJax when any of `texts` is a formula, so it is there before the node is laid out. */\r\nexport function declareFormulas(assets: AssetScope, texts: readonly string[]): void {\r\n if (texts.some((text) => FORMULA.test(text.trim()))) assets.loader(MATHJAX_LOADER, loadMathJax, { gate: \"layout\" });\r\n}\r\n\r\n/** What draws `labels`: text in the scene's face, and a typeset formula for each one written as such. */\r\nexport function drawLabels(labels: readonly Label[], style: LabelStyle): Graphics2D[] {\r\n const out: Graphics2D[] = [];\r\n const fill = Fills.color(style.color);\r\n const text = new Graphics2D();\r\n const width = style.fontSize * LABEL_BOX_EM;\r\n let written = false;\r\n for (const label of labels) {\r\n const formula = FORMULA.exec(label.text.trim());\r\n const glyphs = formula ? typeset(formula[1], label, style.fontSize) : null;\r\n if (glyphs) {\r\n for (const glyph of glyphs) out.push(glyph.fill(fill));\r\n continue;\r\n }\r\n const { at, align } = label;\r\n written = true;\r\n text.text({\r\n text: label.text,\r\n fontSize: style.fontSize,\r\n // An empty family is left out, so the label takes the scene's own face.\r\n ...(style.fontFamily === \"\" ? {} : { fontFamily: style.fontFamily }),\r\n wrap: false,\r\n width,\r\n textAlign: align,\r\n x: align === \"center\" ? at.x : align === \"right\" ? at.x - width / 2 : at.x + width / 2,\r\n y: at.y,\r\n });\r\n }\r\n if (written) out.push(text.fill(fill));\r\n return out;\r\n}\r\n\r\n// A formula's glyphs with its box anchored at the label's point; `null` for one that will not typeset, which is then\r\n// drawn as written, and nothing at all while MathJax is still on its way: its source is not a stand-in for it.\r\nfunction typeset(source: string, { at, align }: Label, fontSize: number): Graphics2D[] | null {\r\n let formula: ReturnType<typeof buildLatexPath>;\r\n try {\r\n formula = buildLatexPath(source, fontSize);\r\n } catch (error) {\r\n return error instanceof LatexNotLoaded ? [] : null;\r\n }\r\n const [minX, minY, maxX, maxY] = formula.bounds;\r\n const dx = at.x + (align === \"left\" ? formula.width / 2 : align === \"right\" ? -formula.width / 2 : 0);\r\n // Glyph paths are y-down; the frame whose centre lands on the node's is shifted the other way.\r\n const frame: [number, number, number, number] = [minX - dx, minY + at.y, maxX - dx, maxY + at.y];\r\n return formula.tokens.map((token) => new Graphics2D().path({ data: toPathString(token.path), centerBounds: frame }));\r\n}\r\n\r\n/** Whether a mark `u` of the way along an axis is inside the part of it drawn so far. */\r\nexport function drawn(u: number, start: number, end: number): boolean {\r\n return u >= start - 1e-9 && u <= end + 1e-9;\r\n}\r\n\r\n/** How far along `range` a value is, 0 to 1, by pixel distance. */\r\nexport function along(at: Vector2, from: Vector2, to: Vector2): number {\r\n const dx = to.x - from.x;\r\n const dy = to.y - from.y;\r\n const length = dx * dx + dy * dy;\r\n return length === 0 ? 0 : ((at.x - from.x) * dx + (at.y - from.y) * dy) / length;\r\n}\r\n\r\nexport function lerpInterval(from: Interval, to: Interval, t: number): Interval {\r\n return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];\r\n}\r\n\r\nexport function readInterval(value: Interval | undefined, previous?: Interval): Interval {\r\n const [min, max] = Array.isArray(value) ? value : (previous ?? [0, 1]);\r\n return [Number(min), Number(max)];\r\n}\r\n", "import {\r\n Graphics2D,\r\n PaintNode,\r\n type BoxBounds,\r\n type ChildPlane,\r\n type Extents,\r\n type MeasureContext2D,\r\n type Node2D,\r\n type PaintProps,\r\n type PathCommand,\r\n type RenderContext2D,\r\n type Size2D,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport { PIXEL_MAP, type CoordinateMap } from \"./coords\";\r\nimport { boundsOfRuns, runsToPath } from \"./geometry\";\r\nimport { openPlane, placeOnMap } from \"./place\";\r\n\r\n/**\r\n * A node drawn in graph coordinates: a plot, an area, an arrow between two\r\n * graph points. It answers with runs of pixel points and is otherwise a shape,\r\n * so fill, stroke, shadow and `progressTo` are the inherited ones and its box\r\n * is the tight box of its ink.\r\n *\r\n * Inside a coordinate system the system lays it out and its own `x`/`y` are a\r\n * shift in graph units, which {@link shift} reports and {@link trace} applies.\r\n * Outside one a graph unit is a pixel and `x`/`y` are the usual offset.\r\n *\r\n * A mark that takes children holds them on the same map it is drawn through: a\r\n * plot holding the area under it and the point that rides it.\r\n */\r\nexport abstract class Mark<P extends PaintProps = PaintProps> extends PaintNode<P> {\r\n /** The runs this mark draws, in pixels, y-up from the system's centre. */\r\n protected abstract trace(map: CoordinateMap): Vector2[][];\r\n\r\n /** Whether each run is closed into an outline. */\r\n protected isClosed(): boolean {\r\n return false;\r\n }\r\n\r\n /** This mark's own `x`/`y` as a shift in graph units: zero outside a system, where they are pixels. */\r\n protected shift(): Vector2 {\r\n return this._inSystem ? { x: this.x, y: this.y } : NO_SHIFT;\r\n }\r\n\r\n /** A graph point in this mark's own frame, where a handle on it sits. */\r\n protected ownPoint(point: Vector2): Vector2 {\r\n const shift = this.shift();\r\n const at = this._map.toPoint(point.x + shift.x, point.y + shift.y);\r\n const centre = this._centre();\r\n return { x: at.x - centre.x, y: at.y - centre.y };\r\n }\r\n\r\n /** The graph point at `at` in this mark's own frame: {@link ownPoint} undone. */\r\n protected graphPoint(at: Vector2): Vector2 {\r\n const shift = this.shift();\r\n const centre = this._centre();\r\n const point = this._map.toCoords(at.x + centre.x, at.y + centre.y);\r\n return { x: point.x - shift.x, y: point.y - shift.y };\r\n }\r\n\r\n /** Whether the fill is painted: a mark whose ink has no inside yet (an open line) says no. */\r\n protected paintsFill(): boolean {\r\n return true;\r\n }\r\n\r\n override measure(): Partial<Size2D> {\r\n const ink = this._resolve(PIXEL_MAP, false);\r\n return ink ? { width: ink.maxX - ink.minX, height: ink.maxY - ink.minY } : { width: 0, height: 0 };\r\n }\r\n\r\n protected override shapeGraphics(): Graphics2D | null {\r\n const ink = this._ink;\r\n if (!ink || this._data.length === 0) return null;\r\n return new Graphics2D().path({\r\n data: this._data,\r\n centerBounds: [ink.minX, ink.minY, ink.maxX, ink.maxY],\r\n start: this.start,\r\n end: this.end,\r\n });\r\n }\r\n\r\n // A mark's stroke is its ink, so it is painted before its children rather\r\n // than over them: a point or a tangent riding a plot sits on the curve.\r\n protected override renderSelf(ctx: RenderContext2D): void {\r\n if (this.paintsFill()) super.renderSelf(ctx);\r\n this.renderInk(ctx);\r\n }\r\n\r\n /** The stroke along the ink. A mark that strokes it differently overrides this, not `renderStroke`. */\r\n protected renderInk(ctx: RenderContext2D): void {\r\n super.renderStroke(ctx);\r\n }\r\n\r\n protected override renderStroke(): void {}\r\n\r\n protected override layoutChildren(rect: BoxBounds, scope: MeasureContext2D): void {\r\n const children = this.flowChildren();\r\n if (children.length === 0) return;\r\n const room = { x: 0, y: 0, width: rect.width, height: rect.height };\r\n this._planes = placeOnMap(children, this._map, this._centre(), room, scope);\r\n }\r\n\r\n override _planeOf(child: Node2D | null): ChildPlane | null {\r\n return child ? (this._planes.get(child) ?? null) : openPlane(this._map, this._centre());\r\n }\r\n\r\n private _data: PathCommand[] = [];\r\n private _ink: Extents | null = null;\r\n private _inSystem = false;\r\n private _map: CoordinateMap = PIXEL_MAP;\r\n private _planes = new WeakMap<Node2D, ChildPlane>();\r\n\r\n /** Its own centre in the map's pixels: where its children's boxes are placed from. */\r\n private _centre(): Vector2 {\r\n const ink = this._ink;\r\n return ink ? { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2 } : NO_SHIFT;\r\n }\r\n\r\n /** @internal What a system lays this mark out on: its ink, drawn through `map`. */\r\n _resolve(map: CoordinateMap, inSystem = true): Extents | null {\r\n this._inSystem = inSystem;\r\n this._map = map;\r\n const runs = this.trace(map);\r\n this._data = runsToPath(runs, this.isClosed());\r\n this._ink = boundsOfRuns(runs);\r\n return this._ink;\r\n }\r\n}\r\n\r\nconst NO_SHIFT: Vector2 = { x: 0, y: 0 };\r\n", "import { expressionOps } from \"@motionscript/sdk\";\r\nimport type { ExpressionDialect, ExpressionNode } from \"@motionscript/sdk\";\r\nimport { createBoundedCache } from \"./cache\";\r\n\r\n/**\r\n * The language a plot's equation is written in: the engine's own expression\r\n * grammar (`expressionOps.parse`) under a dialect of its own, where trig is in\r\n * radians, names are bare identifiers, and the logs and hyperbolics a plot\r\n * wants are present. Never `new Function`: an equation is text stored in a\r\n * document, and the shared parser can only produce arithmetic.\r\n */\r\n\r\n/** Named values an expression reads at call time, beside its two variables. */\r\nexport type ExpressionScope = Readonly<Record<string, number>>;\r\n\r\n/**\r\n * A compiled expression. The two variables are fixed slots because this is the\r\n * hot path of every sampled curve; a one-variable expression never reads `b`.\r\n */\r\nexport type CompiledExpression = (a: number, b: number, scope?: ExpressionScope) => number;\r\n\r\nconst UNARY: Record<string, (v: number) => number> = {\r\n sin: Math.sin, cos: Math.cos, tan: Math.tan,\r\n asin: Math.asin, acos: Math.acos, atan: Math.atan,\r\n sinh: Math.sinh, cosh: Math.cosh, tanh: Math.tanh,\r\n sqrt: Math.sqrt, cbrt: Math.cbrt, abs: Math.abs, exp: Math.exp,\r\n log: Math.log, ln: Math.log, log2: Math.log2, log10: Math.log10,\r\n floor: Math.floor, ceil: Math.ceil, round: Math.round, sign: Math.sign, trunc: Math.trunc,\r\n};\r\n\r\nconst NARY: Record<string, { fn: (...args: number[]) => number; arity: [number, number] }> = {\r\n atan2: { fn: Math.atan2, arity: [2, 2] },\r\n pow: { fn: Math.pow, arity: [2, 2] },\r\n mod: { fn: (a, b) => a % b, arity: [2, 2] },\r\n hypot: { fn: Math.hypot, arity: [1, Infinity] },\r\n min: { fn: Math.min, arity: [1, Infinity] },\r\n max: { fn: Math.max, arity: [1, Infinity] },\r\n};\r\n\r\nconst CONSTANTS: Record<string, number> = {\r\n pi: Math.PI, PI: Math.PI, e: Math.E, E: Math.E, tau: Math.PI * 2, phi: (1 + Math.sqrt(5)) / 2,\r\n};\r\n\r\nexport const MATH_DIALECT: ExpressionDialect = {\r\n functions: {\r\n ...Object.fromEntries(Object.keys(UNARY).map((name) => [name, { arity: [1, 1] as [number, number] }])),\r\n ...Object.fromEntries(Object.entries(NARY).map(([name, { arity }]) => [name, { arity }])),\r\n },\r\n constants: CONSTANTS,\r\n refs: \"bare\",\r\n unknownName: (name) => `Unknown name '${name}'`,\r\n};\r\n\r\n/** What an expression may name, for a host's \"what can I write here\" help. */\r\nexport interface ExpressionVocabulary {\r\n variables: readonly string[];\r\n functions: readonly string[];\r\n constants: readonly string[];\r\n}\r\n\r\nexport function expressionVocabulary(variables: readonly string[]): ExpressionVocabulary {\r\n return {\r\n variables,\r\n functions: [...Object.keys(UNARY), ...Object.keys(NARY)].sort(),\r\n constants: [\"pi\", \"e\", \"tau\", \"phi\"],\r\n };\r\n}\r\n\r\n/**\r\n * Compile `source` over up to two `variables`, in slot order, and any `params`\r\n * it may read from the scope. Throws on a syntax error or an unknown name.\r\n */\r\nexport function compileExpression(\r\n source: string,\r\n variables: readonly string[],\r\n params: readonly string[] = [],\r\n): CompiledExpression {\r\n // The parser folds a constant before it yields a reference, so a name that\r\n // is both would silently stop being the variable it was passed as.\r\n for (const name of [...variables, ...params]) {\r\n if (Object.hasOwn(CONSTANTS, name)) throw new Error(`'${name}' is a constant, so it cannot be a variable`);\r\n }\r\n return emit(expressionOps.parse(source, MATH_DIALECT).root, variables, params);\r\n}\r\n\r\nfunction emit(node: ExpressionNode, variables: readonly string[], params: readonly string[]): CompiledExpression {\r\n switch (node.kind) {\r\n case \"const\": {\r\n const { value } = node;\r\n return () => value;\r\n }\r\n case \"ref\": {\r\n const { name } = node;\r\n const slot = variables.indexOf(name);\r\n if (slot === 0) return (a) => a;\r\n if (slot === 1) return (_a, b) => b;\r\n if (params.includes(name)) return (_a, _b, scope) => scope?.[name] ?? NaN;\r\n throw new Error(MATH_DIALECT.unknownName(name));\r\n }\r\n case \"unary\": {\r\n const operand = emit(node.operand, variables, params);\r\n return (a, b, s) => -operand(a, b, s);\r\n }\r\n case \"binary\": {\r\n const l = emit(node.left, variables, params);\r\n const r = emit(node.right, variables, params);\r\n switch (node.op) {\r\n case \"+\": return (a, b, s) => l(a, b, s) + r(a, b, s);\r\n case \"-\": return (a, b, s) => l(a, b, s) - r(a, b, s);\r\n case \"*\": return (a, b, s) => l(a, b, s) * r(a, b, s);\r\n case \"/\": return (a, b, s) => l(a, b, s) / r(a, b, s);\r\n case \"%\": return (a, b, s) => l(a, b, s) % r(a, b, s);\r\n case \"^\": return (a, b, s) => Math.pow(l(a, b, s), r(a, b, s));\r\n }\r\n break;\r\n }\r\n case \"call\": {\r\n const args = node.args.map((arg) => emit(arg, variables, params));\r\n const unary = UNARY[node.name];\r\n if (unary) {\r\n const [x] = args;\r\n return (a, b, s) => unary(x(a, b, s));\r\n }\r\n const { fn } = NARY[node.name];\r\n // The common arity, so the hot path allocates no array per sample.\r\n if (args.length === 2) {\r\n const [x, y] = args;\r\n return (a, b, s) => fn(x(a, b, s), y(a, b, s));\r\n }\r\n return (a, b, s) => fn(...args.map((arg) => arg(a, b, s)));\r\n }\r\n }\r\n throw new Error(\"Unsupported expression\");\r\n}\r\n\r\nconst compiled = createBoundedCache<CompiledExpression | Error>(256);\r\n\r\n/**\r\n * {@link compileExpression}, memoised: equal source under equal names is the\r\n * identical closure, so \"did this expression change\" is an `===`, and a failure\r\n * is remembered rather than re-parsed every frame.\r\n */\r\nexport function compileExpressionCached(\r\n source: string,\r\n variables: readonly string[],\r\n params: readonly string[] = [],\r\n): CompiledExpression | Error {\r\n const key = `${variables.join(\",\")}|${params.join(\",\")}|${source}`;\r\n const hit = compiled.get(key);\r\n if (hit !== undefined) return hit;\r\n let result: CompiledExpression | Error;\r\n try {\r\n result = compileExpression(source, variables, params);\r\n } catch (error) {\r\n result = error instanceof Error ? error : new Error(String(error));\r\n }\r\n compiled.set(key, result);\r\n return result;\r\n}\r\n", "import { expressionOps, type ExpressionNode } from \"@motionscript/sdk\";\r\nimport { createBoundedCache } from \"./cache\";\r\nimport { compileExpressionCached, MATH_DIALECT, type CompiledExpression } from \"./expression\";\r\n\r\n/**\r\n * A plotted equation, read the way it is written rather than by a `kind` prop:\r\n *\r\n * | Written as | Is |\r\n * |---|---|\r\n * | `sin(x)`, `y = sin(x)` | a function of `x` |\r\n * | `x = y^2` | a function of `y` |\r\n * | `r = 1 + cos(theta)` | polar, in `theta` |\r\n * | `(cos(t), sin(t))` | parametric, in `t` |\r\n * | `x^2 + y^2 = 4` | implicit, in `x` and `y` |\r\n */\r\nexport type Equation =\r\n | { kind: \"function\"; of: \"x\" | \"y\"; f: CompiledExpression }\r\n | { kind: \"polar\"; f: CompiledExpression }\r\n | { kind: \"parametric\"; x: CompiledExpression; y: CompiledExpression }\r\n /** Drawn where `f(x, y)` is zero. */\r\n | { kind: \"implicit\"; f: CompiledExpression };\r\n\r\n/** The free variable each kind is sampled over, for a host's help text. */\r\nexport const EQUATION_VARIABLES = {\r\n function: [\"x\"],\r\n polar: [\"theta\"],\r\n parametric: [\"t\"],\r\n implicit: [\"x\", \"y\"],\r\n} as const satisfies Record<Equation[\"kind\"], readonly string[]>;\r\n\r\nconst parsed = createBoundedCache<Equation | Error>(256);\r\n\r\n/**\r\n * `source` as an {@link Equation}, or the reason it is not one. Memoised, so an\r\n * unchanged equation is the identical object and a geometry cache can key on it.\r\n */\r\nexport function parseEquation(source: string, params: readonly string[] = []): Equation | Error {\r\n const key = `${params.join(\",\")}|${source}`;\r\n const hit = parsed.get(key);\r\n if (hit !== undefined) return hit;\r\n let result: Equation | Error;\r\n try {\r\n result = read(source.trim(), params);\r\n } catch (error) {\r\n result = error instanceof Error ? error : new Error(String(error));\r\n }\r\n parsed.set(key, result);\r\n return result;\r\n}\r\n\r\n/**\r\n * Why `source` will not plot, or `null` when it will. An empty one is not an\r\n * error (nobody has written it yet), and neither is a name it does not know:\r\n * that is a named value, see {@link equationParams}.\r\n */\r\nexport function equationError(source: string): string | null {\r\n if (source.trim() === \"\") return null;\r\n const equation = parseEquation(source, equationParams(source));\r\n return equation instanceof Error ? equation.message : null;\r\n}\r\n\r\n/** A name that is always a variable of some kind of equation, so never a named value. */\r\nconst VARIABLE_NAMES: ReadonlySet<string> = new Set([\"r\", ...Object.values(EQUATION_VARIABLES).flat()]);\r\n\r\nconst named = createBoundedCache<readonly string[]>(256);\r\n\r\n/**\r\n * Every name `source` reads, in the order it first names them, variables\r\n * included. Empty for text that does not parse.\r\n */\r\nexport function equationNames(source: string): readonly string[] {\r\n const hit = named.get(source);\r\n if (hit !== undefined) return hit;\r\n const names = new Set<string>();\r\n const text = source.trim();\r\n try {\r\n for (const part of splitTuple(text) ?? splitTopLevel(text, \"=\")) {\r\n collectNames(expressionOps.parse(part.trim(), MATH_DIALECT).root, names);\r\n }\r\n } catch {\r\n names.clear();\r\n }\r\n const result = [...names];\r\n named.set(source, result);\r\n return result;\r\n}\r\n\r\n/**\r\n * The named values `source` reads: every name that is not a variable, a\r\n * function or a constant.\r\n */\r\nexport function equationParams(source: string): readonly string[] {\r\n return equationNames(source).filter((name) => !VARIABLE_NAMES.has(name));\r\n}\r\n\r\nfunction collectNames(node: ExpressionNode, into: Set<string>): void {\r\n switch (node.kind) {\r\n case \"ref\":\r\n into.add(node.name);\r\n return;\r\n case \"unary\":\r\n collectNames(node.operand, into);\r\n return;\r\n case \"binary\":\r\n collectNames(node.left, into);\r\n collectNames(node.right, into);\r\n return;\r\n case \"call\":\r\n for (const arg of node.args) collectNames(arg, into);\r\n return;\r\n default:\r\n }\r\n}\r\n\r\nfunction read(source: string, params: readonly string[]): Equation {\r\n if (source === \"\") throw new Error(\"Empty equation\");\r\n const compile = (text: string, variables: readonly string[]): CompiledExpression => {\r\n const result = compileExpressionCached(text.trim(), variables, params);\r\n if (result instanceof Error) throw result;\r\n return result;\r\n };\r\n\r\n const pair = splitTuple(source);\r\n if (pair?.length === 2) return { kind: \"parametric\", x: compile(pair[0], [\"t\"]), y: compile(pair[1], [\"t\"]) };\r\n\r\n const sides = splitTopLevel(source, \"=\");\r\n if (sides.length > 2) throw new Error(\"An equation has one '='\");\r\n if (sides.length === 1) return { kind: \"function\", of: \"x\", f: compile(source, [\"x\"]) };\r\n\r\n const [left, right] = sides;\r\n const subject = left.trim();\r\n const implicit = (): Equation => {\r\n const l = compile(left, [\"x\", \"y\"]);\r\n const r = compile(right, [\"x\", \"y\"]);\r\n return { kind: \"implicit\", f: (x, y, scope) => l(x, y, scope) - r(x, y, scope) };\r\n };\r\n if (subject === \"r\") return { kind: \"polar\", f: compile(right, [\"theta\"]) };\r\n if (subject === \"y\" || subject === \"x\") {\r\n const of = subject === \"y\" ? \"x\" : \"y\";\r\n // `y = x + y` names its own subject on the right, so it is not a function of one variable.\r\n try {\r\n return { kind: \"function\", of, f: compile(right, [of]) };\r\n } catch (error) {\r\n try {\r\n return implicit();\r\n } catch {\r\n throw error;\r\n }\r\n }\r\n }\r\n return implicit();\r\n}\r\n\r\n/** `(a, b, …)` as its parts, or `null` when `source` is not one parenthesised list of two or more. */\r\nexport function splitTuple(source: string): string[] | null {\r\n if (!source.startsWith(\"(\") || !source.endsWith(\")\")) return null;\r\n let depth = 0;\r\n for (let i = 0; i < source.length - 1; i++) {\r\n if (source[i] === \"(\") depth++;\r\n else if (source[i] === \")\" && --depth === 0) return null;\r\n }\r\n const parts = splitTopLevel(source.slice(1, -1), \",\");\r\n return parts.length >= 2 ? parts : null;\r\n}\r\n\r\nexport function splitTopLevel(source: string, separator: string): string[] {\r\n const parts: string[] = [];\r\n let depth = 0;\r\n let from = 0;\r\n for (let i = 0; i < source.length; i++) {\r\n const c = source[i];\r\n if (c === \"(\") depth++;\r\n else if (c === \")\") depth--;\r\n else if (c === separator && depth === 0) {\r\n parts.push(source.slice(from, i));\r\n from = i + 1;\r\n }\r\n }\r\n parts.push(source.slice(from));\r\n return parts;\r\n}\r\n", "import type { Interval } from \"./coords\";\r\nimport type { ExpressionScope } from \"./expression\";\r\n\r\n/** What a plot's equation, domain and named values are held as, and how each tweens: shared by every plot, 2D and 3D. */\r\n\r\n/** An equation on its way to another: both are drawn, `t` of the way across. */\r\nexport interface PlotSource {\r\n source: string;\r\n blend?: { from: string; t: number };\r\n}\r\n\r\nexport function readSource(value: string | PlotSource | undefined): PlotSource {\r\n if (typeof value === \"string\") return { source: value };\r\n return value ?? { source: \"\" };\r\n}\r\n\r\n// Mid-tween the prop holds both equations, so a seek restores the blend with it.\r\nexport function lerpSource(from: PlotSource, to: PlotSource, t: number): PlotSource {\r\n if (t <= 0 || from.source === to.source) return t <= 0 ? from : to;\r\n return t >= 1 ? to : { source: to.source, blend: { from: from.source, t } };\r\n}\r\n\r\nexport function lerpDomain(from: Interval | null, to: Interval | null, t: number): Interval | null {\r\n if (!from || !to) return t < 1 ? from : to;\r\n return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];\r\n}\r\n\r\n/** What a named value is until it is given one. */\r\nexport const UNSET_PARAM = 1;\r\n\r\nexport function lerpParams(from: ExpressionScope, to: ExpressionScope, t: number): ExpressionScope {\r\n const out: Record<string, number> = { ...from };\r\n for (const [name, value] of Object.entries(to)) {\r\n const start = from[name] ?? UNSET_PARAM;\r\n out[name] = start + (value - start) * t;\r\n }\r\n return out;\r\n}\r\n\r\n/** `params` with every name of `names` given a value, so one nobody has set yet still draws. */\r\nexport function scopeFor(names: readonly string[], params: ExpressionScope): ExpressionScope {\r\n let filled: Record<string, number> | null = null;\r\n for (const name of names) {\r\n if (typeof params[name] !== \"number\") (filled ??= { ...params })[name] = UNSET_PARAM;\r\n }\r\n return filled ?? params;\r\n}\r\n\r\n/** A string as a number that changes when it does: what a geometry's `revision` wants. */\r\nexport function revisionOf(key: string): number {\r\n let hash = 0x811c9dc5;\r\n for (let i = 0; i < key.length; i++) {\r\n hash ^= key.charCodeAt(i);\r\n hash = Math.imul(hash, 0x01000193);\r\n }\r\n return hash >>> 0;\r\n}\r\n", "import type { Extents, Vector2 } from \"@motionscript/sdk\";\r\n\r\n/**\r\n * Turns a curve into the polylines that draw it: adaptively, so a straight\r\n * stretch costs two points and a tight bend as many as it needs, and broken\r\n * wherever the curve is, at an asymptote or the edge of its domain.\r\n */\r\n\r\n/** A curve's parameter to its pixel, written into `out`. `false` where the curve is undefined. */\r\nexport type CurveProjection = (t: number, out: Vector2) => boolean;\r\n\r\nexport interface SampleOptions {\r\n /** The equal steps the parameter range starts as, before any is split. */\r\n seeds?: number;\r\n /** A parameter step that is not split again, however bent. */\r\n minStep?: number;\r\n}\r\n\r\n/** Skia's path coordinates are 32-bit floats; past this a clamped point still clips to the same edge. */\r\nconst COORD_LIMIT = 16_000;\r\n/** How far, in pixels, the drawn chord may stray from the curve. */\r\nconst TOLERANCE_PX = 0.25;\r\n/** A turn, in radians, a chord is allowed to hide: what keeps a symmetric bump from reading as flat. */\r\nconst ANGLE_TOLERANCE = 0.05;\r\nconst MAX_DEPTH = 12;\r\nconst MAX_EVALUATIONS = 40_000;\r\nconst MAX_POINTS = 24_000;\r\n/** Bisections spent finding where a domain ends. */\r\nconst BOUNDARY_STEPS = 60;\r\nconst DEFAULT_SEEDS = 256;\r\n\r\ninterface Sample {\r\n t: number;\r\n px: number;\r\n py: number;\r\n /** The pixel before clamping: what tells an asymptote from a steep line. */\r\n rx: number;\r\n ry: number;\r\n ok: boolean;\r\n}\r\n\r\n// Midpoints are pooled: a refine is a depth-first walk, so a slot is free again\r\n// as soon as the seed interval it was taken for is done.\r\nconst arena: Sample[] = [];\r\nlet arenaMark = 0;\r\n\r\nfunction takeSample(): Sample {\r\n let slot = arena[arenaMark];\r\n if (slot === undefined) {\r\n slot = blank();\r\n arena.push(slot);\r\n }\r\n arenaMark++;\r\n return slot;\r\n}\r\n\r\nfunction blank(): Sample {\r\n return { t: 0, px: 0, py: 0, rx: 0, ry: 0, ok: false };\r\n}\r\n\r\nconst scratch: Vector2 = { x: 0, y: 0 };\r\n\r\n/** The runs of points that draw `project` over `[t0, t1]`, clipped to `clip`. */\r\nexport function sampleCurve(\r\n project: CurveProjection,\r\n t0: number,\r\n t1: number,\r\n clip: Extents,\r\n { seeds = DEFAULT_SEEDS, minStep = 0 }: SampleOptions = {},\r\n): Vector2[][] {\r\n if (!(t1 > t0) || !Number.isFinite(t0) || !Number.isFinite(t1)) return [];\r\n const pen = new CurvePen(clip);\r\n let spent = 0;\r\n\r\n const write = (slot: Sample, t: number): Sample => {\r\n const defined = project(t, scratch);\r\n spent++;\r\n const ok = defined && Number.isFinite(scratch.x) && Number.isFinite(scratch.y);\r\n slot.t = t;\r\n slot.rx = ok ? scratch.x : 0;\r\n slot.ry = ok ? scratch.y : 0;\r\n slot.px = clampCoord(slot.rx);\r\n slot.py = clampCoord(slot.ry);\r\n slot.ok = ok;\r\n return slot;\r\n };\r\n const at = (t: number): Sample => write(takeSample(), t);\r\n\r\n // The last defined point before `to`, which is not: where `sqrt(x)` meets its axis.\r\n const edgeOf = (from: Sample, to: Sample): Sample => {\r\n let inside = from;\r\n let outsideT = to.t;\r\n for (let i = 0; i < BOUNDARY_STEPS; i++) {\r\n if (spent >= MAX_EVALUATIONS || offFrame(inside, clip)) break;\r\n const midT = (inside.t + outsideT) / 2;\r\n if (midT === inside.t || midT === outsideT) break;\r\n const mid = at(midT);\r\n if (!mid.ok) {\r\n outsideT = midT;\r\n continue;\r\n }\r\n const settled = Math.abs(mid.px - inside.px) < TOLERANCE_PX && Math.abs(mid.py - inside.py) < TOLERANCE_PX;\r\n inside = mid;\r\n if (settled) break;\r\n }\r\n return inside;\r\n };\r\n\r\n const emit = (a: Sample, m: Sample | null, b: Sample, floored: boolean): void => {\r\n if (a.ok && b.ok) {\r\n if (floored && diverges(a, m, b, clip)) pen.break();\r\n else pen.draw(a, b);\r\n return;\r\n }\r\n if (a.ok) {\r\n const edge = edgeOf(a, b);\r\n if (edge.t !== a.t) pen.draw(a, edge);\r\n pen.break();\r\n return;\r\n }\r\n pen.break();\r\n if (b.ok) {\r\n const edge = edgeOf(b, a);\r\n if (edge.t !== b.t) pen.draw(edge, b);\r\n else pen.start(b);\r\n }\r\n };\r\n\r\n const refine = (a: Sample, b: Sample, depth: number): void => {\r\n if (spent >= MAX_EVALUATIONS || pen.points >= MAX_POINTS) {\r\n emit(a, null, b, false);\r\n return;\r\n }\r\n const m = at((a.t + b.t) / 2);\r\n const floored = depth >= MAX_DEPTH || b.t - a.t <= minStep;\r\n if (floored || flat(a, m, b)) {\r\n emit(a, m, b, floored);\r\n return;\r\n }\r\n refine(a, m, depth + 1);\r\n refine(m, b, depth + 1);\r\n };\r\n\r\n const count = Math.max(1, Math.round(seeds));\r\n const step = (t1 - t0) / count;\r\n const ends: [Sample, Sample] = [blank(), blank()];\r\n let previous = write(ends[0], t0);\r\n for (let i = 1; i <= count; i++) {\r\n const next = write(ends[i & 1], i === count ? t1 : t0 + i * step);\r\n arenaMark = 0;\r\n refine(previous, next, 0);\r\n previous = next;\r\n }\r\n arenaMark = 0;\r\n return pen.finish();\r\n}\r\n\r\nfunction flat(a: Sample, m: Sample, b: Sample): boolean {\r\n if (a.ok !== m.ok || m.ok !== b.ok) return false;\r\n if (!a.ok) return true;\r\n const dx = b.px - a.px;\r\n const dy = b.py - a.py;\r\n const length = Math.hypot(dx, dy) || 1;\r\n if (Math.abs((m.px - a.px) * dy - (m.py - a.py) * dx) / length > TOLERANCE_PX) return false;\r\n let turn = Math.abs(Math.atan2(m.py - a.py, m.px - a.px) - Math.atan2(b.py - m.py, b.px - m.px));\r\n if (turn > Math.PI) turn = 2 * Math.PI - turn;\r\n return turn < ANGLE_TOLERANCE;\r\n}\r\n\r\n// Two neighbours on opposite sides of the frame, with nothing between them that\r\n// is between them: an asymptote, not a steep line.\r\nfunction diverges(a: Sample, m: Sample | null, b: Sample, clip: Extents): boolean {\r\n const straddles =\r\n (a.py > clip.maxY && b.py < clip.minY) || (a.py < clip.minY && b.py > clip.maxY) ||\r\n (a.px > clip.maxX && b.px < clip.minX) || (a.px < clip.minX && b.px > clip.maxX);\r\n if (!straddles || m === null) return false;\r\n if (!m.ok) return true;\r\n return (\r\n m.ry < Math.min(a.ry, b.ry) || m.ry > Math.max(a.ry, b.ry) ||\r\n m.rx < Math.min(a.rx, b.rx) || m.rx > Math.max(a.rx, b.rx)\r\n );\r\n}\r\n\r\nfunction offFrame(sample: Sample, clip: Extents): boolean {\r\n return sample.py > clip.maxY || sample.py < clip.minY || sample.px > clip.maxX || sample.px < clip.minX;\r\n}\r\n\r\nfunction clampCoord(value: number): number {\r\n if (value > COORD_LIMIT) return COORD_LIMIT;\r\n if (value < -COORD_LIMIT) return -COORD_LIMIT;\r\n return value;\r\n}\r\n\r\nclass CurvePen {\r\n points = 0;\r\n private readonly runs: Vector2[][] = [];\r\n private open: Vector2[] = [];\r\n private cursor: Vector2 | null = null;\r\n\r\n constructor(private readonly clip: Extents) {}\r\n\r\n draw(a: Sample, b: Sample): void {\r\n const segment = clipSegment(a.px, a.py, b.px, b.py, this.clip);\r\n if (!segment) {\r\n this.break();\r\n return;\r\n }\r\n const [start, end] = segment;\r\n if (this.cursor && samePoint(this.cursor, start)) {\r\n this.push(end);\r\n } else {\r\n this.break();\r\n this.push(start);\r\n this.push(end);\r\n }\r\n this.cursor = end;\r\n }\r\n\r\n start(b: Sample): void {\r\n this.break();\r\n if (!inside(b.px, b.py, this.clip)) return;\r\n this.cursor = { x: b.px, y: b.py };\r\n this.push(this.cursor);\r\n }\r\n\r\n break(): void {\r\n if (this.open.length >= 2) this.runs.push(this.open);\r\n this.open = [];\r\n this.cursor = null;\r\n }\r\n\r\n finish(): Vector2[][] {\r\n this.break();\r\n return this.runs;\r\n }\r\n\r\n private push(point: Vector2): void {\r\n this.open.push(point);\r\n this.points++;\r\n }\r\n}\r\n\r\nfunction samePoint(a: Vector2, b: Vector2): boolean {\r\n return Math.abs(a.x - b.x) < 0.1 && Math.abs(a.y - b.y) < 0.1;\r\n}\r\n\r\nfunction inside(x: number, y: number, clip: Extents): boolean {\r\n return x >= clip.minX && x <= clip.maxX && y >= clip.minY && y <= clip.maxY;\r\n}\r\n\r\n// Liang–Barsky: the part of a segment inside the clip, or null when none is.\r\nfunction clipSegment(ax: number, ay: number, bx: number, by: number, clip: Extents): [Vector2, Vector2] | null {\r\n const dx = bx - ax;\r\n const dy = by - ay;\r\n let t0 = 0;\r\n let t1 = 1;\r\n const edges: [number, number][] = [\r\n [-dx, ax - clip.minX],\r\n [dx, clip.maxX - ax],\r\n [-dy, ay - clip.minY],\r\n [dy, clip.maxY - ay],\r\n ];\r\n for (const [p, q] of edges) {\r\n if (p === 0) {\r\n if (q < 0) return null;\r\n continue;\r\n }\r\n const r = q / p;\r\n if (p < 0) {\r\n if (r > t1) return null;\r\n if (r > t0) t0 = r;\r\n } else {\r\n if (r < t0) return null;\r\n if (r < t1) t1 = r;\r\n }\r\n }\r\n return [\r\n { x: ax + t0 * dx, y: ay + t0 * dy },\r\n { x: ax + t1 * dx, y: ay + t1 * dy },\r\n ];\r\n}\r\n", "import { findNode2D, type Node2D } from \"@motionscript/sdk\";\r\n\r\n/**\r\n * A node with a height at each `x`: what a point, a tangent or an area rides.\r\n * A protocol rather than a class, so a copied plot is ridden like the kit's own.\r\n */\r\nexport interface Curve {\r\n /** The curve's height at graph `x`, or `NaN` where it has none. */\r\n valueAt(x: number): number;\r\n}\r\n\r\n/** The curve `id` names in `from`'s tree, or `null`. */\r\nexport function curveNamed(from: Node2D, id: string): Curve | null {\r\n if (id === \"\") return null;\r\n const found = findNode2D(from, id) as (Node2D & Partial<Curve>) | null;\r\n return found && typeof found.valueAt === \"function\" ? (found as Node2D & Curve) : null;\r\n}\r\n\r\n/**\r\n * The curve a mark reads: the one `on` names, or, naming none, the nearest\r\n * curve the mark sits inside. Putting an area in a plot is how it is told which.\r\n */\r\nexport function curveOf(mark: Node2D, on: string): Curve | null {\r\n if (on !== \"\") return curveNamed(mark, on);\r\n for (let at: Node2D | null = mark.parent; at; at = at.parent) {\r\n if (typeof (at as Partial<Curve>).valueAt === \"function\") return at as Node2D & Curve;\r\n }\r\n return null;\r\n}\r\n", "import {\r\n command,\r\n findNode2D,\r\n frameIn,\r\n Graphics2D,\r\n PaintNode,\r\n pathOps,\r\n property,\r\n withdraw,\r\n type BoxBounds,\r\n type Command,\r\n type CommandArgs,\r\n type Node2D,\r\n type PaintProps,\r\n type PathCommand,\r\n type Size2D,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport { FILL_PAINT } from \"./withdrawn\";\r\n\r\n/** A node with parts that can be pointed at by name: a formula's terms. */\r\nexport interface Parted {\r\n /** The box of `part`, y-up from the node's centre, or `null` when it has no such part. */\r\n partBounds(part: string, occurrence?: number): BoxBounds | null;\r\n}\r\n\r\nfunction isParted(node: object): node is Parted {\r\n return typeof (node as Partial<Parted>).partBounds === \"function\";\r\n}\r\n\r\n/** What a mark is drawn on: a node by id, and one part of it where it has parts. */\r\nexport interface Target {\r\n on: string;\r\n part?: string;\r\n occurrence?: number;\r\n}\r\n\r\n/** A target on its way to another: `t` of the way from `from`, or from the mark's resting target. */\r\nexport interface Retarget extends Target {\r\n from?: Target | null;\r\n t: number;\r\n}\r\n\r\n/** A target's four corners in its mark's own frame, y-up: top left, top right, bottom right, bottom left. */\r\nexport type Quad = [Vector2, Vector2, Vector2, Vector2];\r\n\r\n/**\r\n * The node a mark is drawn on: the one `on` names, or, naming none, the nearest\r\n * node with parts the mark sits inside. Putting a box in a formula is how it is\r\n * told which.\r\n */\r\nexport function followed(mark: Node2D, on: string): Node2D | null {\r\n if (on !== \"\") {\r\n const node = findNode2D(mark, on);\r\n return node && node !== mark ? node : null;\r\n }\r\n for (let at: Node2D | null = mark.parent; at; at = at.parent) {\r\n if (isParted(at)) return at;\r\n }\r\n return null;\r\n}\r\n\r\n/** Where `target` is, as `mark` sees it; `null` when it names no node or part. */\r\nexport function quadOf(mark: Node2D, target: Target): Quad | null {\r\n const node = followed(mark, target.on);\r\n if (!node) return null;\r\n const box: BoxBounds | null =\r\n target.part && isParted(node)\r\n ? node.partBounds(target.part, target.occurrence || 1)\r\n : { x: 0, y: 0, width: node.layoutBounds.width, height: node.layoutBounds.height };\r\n if (!box) return null;\r\n const frame = frameIn(mark, node);\r\n const turn = (frame.rotation * Math.PI) / 180;\r\n const cos = Math.cos(turn);\r\n const sin = Math.sin(turn);\r\n // The engine's turn is clockwise, in a y-up frame.\r\n const place = (x: number, y: number): Vector2 => ({\r\n x: frame.x + (cos * x + sin * y) * frame.scale,\r\n y: frame.y + (-sin * x + cos * y) * frame.scale,\r\n });\r\n const w = box.width / 2;\r\n const h = box.height / 2;\r\n return [place(box.x - w, box.y + h), place(box.x + w, box.y + h), place(box.x + w, box.y - h), place(box.x - w, box.y - h)];\r\n}\r\n\r\nfunction lerpQuad(a: Quad, b: Quad, t: number): Quad {\r\n return a.map((from, i) => ({ x: from.x + (b[i].x - from.x) * t, y: from.y + (b[i].y - from.y) * t })) as Quad;\r\n}\r\n\r\nconst restOf = ({ on, part, occurrence }: Target): Target => ({ on, part, occurrence });\r\n\r\nfunction lerpRetarget(from: Retarget | null, to: Retarget | null, t: number): Retarget | null {\r\n if (t <= 0 || !to) return t < 1 ? from : to;\r\n return { ...restOf(to), from: from ? restOf(from) : null, t };\r\n}\r\n\r\nexport interface FollowProps extends PaintProps {\r\n on?: string;\r\n part?: string;\r\n occurrence?: number;\r\n retarget?: Retarget | null;\r\n}\r\n\r\n/** Every drawn point's centre frame: the mark's own centre, so its outline is where it says. */\r\nconst OWN_FRAME: [number, number, number, number] = [-1, -1, 1, 1];\r\n\r\n/**\r\n * A mark drawn on another node, or on one part of a formula: a brace, a box,\r\n * an underline. It has no size of its own and takes no place in a layout; it\r\n * is drawn where its target is, wherever the two are in the tree, and its\r\n * selection box is its ink.\r\n */\r\n@withdraw(...FILL_PAINT)\r\nexport abstract class FollowMark<P extends FollowProps = FollowProps> extends PaintNode<P> {\r\n /** The node this mark is drawn on, by id. Left empty, it is the formula the mark sits inside. */\r\n @property({ default: \"\", kind: \"nodeRef\", animatable: false }) declare on: string;\r\n /** One part of that node, by its source, where it has parts: `x^2` of a formula. */\r\n @property({ default: \"\", animatable: false }) declare part: string;\r\n /** Which of the places the part is written, counted from 1. */\r\n @property({ default: 1, min: 1, step: 1, animatable: false }) declare occurrence: number;\r\n /** Where a `retargetTo` has taken the mark, and how far along it is. Not an author's to state. */\r\n @property({ default: null, tween: lerpRetarget }) declare retarget: Retarget | null;\r\n\r\n /** Move the mark onto another node, or another part. */\r\n @command({\r\n args: [\r\n { key: \"on\", kind: \"nodeRef\" },\r\n { key: \"part\", kind: \"text\", default: \"\" },\r\n { key: \"occurrence\", kind: \"number\", min: 1, step: 1, default: 1 },\r\n ],\r\n })\r\n retargetTo(args: CommandArgs<Partial<Target>> & { duration: number }): Command<P> {\r\n const next = args.data ?? {};\r\n const held = this.retarget ?? this;\r\n const to: Retarget = {\r\n on: next.on ?? held.on,\r\n part: next.part ?? (next.on ? \"\" : held.part),\r\n occurrence: next.occurrence ?? 1,\r\n t: 1,\r\n };\r\n return this.to({ data: { retarget: to } as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** The outline to draw around `quad`, in the mark's own frame, y-up. */\r\n protected abstract outline(quad: Quad): PathCommand[];\r\n\r\n /** The target's corners now: its resting one, or part-way to where a `retargetTo` is taking it. */\r\n protected quad(): Quad | null {\r\n const state = this.retarget;\r\n if (!state) return quadOf(this, this);\r\n const to = quadOf(this, state);\r\n const from = quadOf(this, state.from ?? this);\r\n if (!from || !to || state.t >= 1) return to ?? from;\r\n return lerpQuad(from, to, state.t);\r\n }\r\n\r\n override measure(): Partial<Size2D> {\r\n return { width: 0, height: 0 };\r\n }\r\n\r\n protected override shapeGraphics(): Graphics2D | null {\r\n const data = this._outline();\r\n if (data.length === 0) return null;\r\n return new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: this.start, end: this.end });\r\n }\r\n\r\n override _localBounds(): BoxBounds {\r\n const ink = pathOps.bounds(this._outline());\r\n if (!ink) return { x: 0, y: 0, width: 0, height: 0 };\r\n return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };\r\n }\r\n\r\n private _outline(): PathCommand[] {\r\n const quad = this.quad();\r\n return quad ? this.outline(quad) : [];\r\n }\r\n}\r\n\r\n// --- Geometry the marks share ---\r\n\r\nexport const add = (a: Vector2, b: Vector2, k = 1): Vector2 => ({ x: a.x + b.x * k, y: a.y + b.y * k });\r\nexport const between = (a: Vector2, b: Vector2, t = 0.5): Vector2 => ({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t });\r\n\r\n/** The unit vector from `a` to `b`, and its length; a zero one points right. */\r\nexport function heading(a: Vector2, b: Vector2): { unit: Vector2; length: number } {\r\n const dx = b.x - a.x;\r\n const dy = b.y - a.y;\r\n const length = Math.hypot(dx, dy);\r\n return { unit: length === 0 ? { x: 1, y: 0 } : { x: dx / length, y: dy / length }, length };\r\n}\r\n\r\n/** A quad grown by `by` pixels on every side, along its own edges. */\r\nexport function grown(quad: Quad, by: number): Quad {\r\n const [tl, tr, br, bl] = quad;\r\n const across = heading(tl, tr).unit;\r\n const up = heading(bl, tl).unit;\r\n return [\r\n add(add(tl, across, -by), up, by),\r\n add(add(tr, across, by), up, by),\r\n add(add(br, across, by), up, -by),\r\n add(add(bl, across, -by), up, -by),\r\n ];\r\n}\r\n", "import { createBoundedCache } from \"./cache\";\r\nimport { equationNames, splitTuple } from \"./equation\";\r\nimport { compileExpressionCached, type CompiledExpression } from \"./expression\";\r\n\r\n/** A vector at every point of the plane, two parts in `x` and `y`: `(-y, x)`. A warp is written the same way. */\r\nexport interface FieldEquation {\r\n x: CompiledExpression;\r\n y: CompiledExpression;\r\n}\r\n\r\nexport const FIELD_VARIABLES = [\"x\", \"y\"] as const;\r\n\r\nconst NAMES: ReadonlySet<string> = new Set(FIELD_VARIABLES);\r\nconst fields = createBoundedCache<FieldEquation | Error>(128);\r\n\r\n/** The named values a field's equation reads: every name that is not `x` or `y`. */\r\nexport function fieldParams(source: string): readonly string[] {\r\n return equationNames(source).filter((name) => !NAMES.has(name));\r\n}\r\n\r\n/** `source` as a field, or the reason it is not one. Memoised, so an unchanged equation is the identical object. */\r\nexport function parseField(source: string, params: readonly string[] = []): FieldEquation | Error {\r\n const key = `${params.join(\",\")}|${source}`;\r\n const hit = fields.get(key);\r\n if (hit !== undefined) return hit;\r\n let result: FieldEquation | Error;\r\n try {\r\n const text = source.trim();\r\n if (text === \"\") throw new Error(\"Empty equation\");\r\n const parts = splitTuple(text);\r\n if (parts?.length !== 2) throw new Error(\"A field has two parts: (x, y)\");\r\n const [x, y] = parts.map((part) => {\r\n const compiled = compileExpressionCached(part.trim(), FIELD_VARIABLES, params);\r\n if (compiled instanceof Error) throw compiled;\r\n return compiled;\r\n });\r\n result = { x, y };\r\n } catch (error) {\r\n result = error instanceof Error ? error : new Error(String(error));\r\n }\r\n fields.set(key, result);\r\n return result;\r\n}\r\n\r\n/** Why `source` is not a field, or `null`; empty text is not an error. */\r\nexport function fieldError(source: string): string | null {\r\n if (source.trim() === \"\") return null;\r\n const field = parseField(source, fieldParams(source));\r\n return field instanceof Error ? field.message : null;\r\n}\r\n", "import { createBoundedCache } from \"./cache\";\r\nimport { equationError, equationNames, equationParams, EQUATION_VARIABLES, splitTopLevel, splitTuple } from \"./equation\";\r\nimport { compileExpressionCached, type CompiledExpression } from \"./expression\";\r\nimport { fieldError, fieldParams, FIELD_VARIABLES } from \"./field\";\r\n\r\n/**\r\n * A surface's equation, read the way it is written:\r\n *\r\n * | Written as | Is |\r\n * |---|---|\r\n * | `sin(x) * cos(y)`, `z = x^2 - y^2` | a height over `x` and `y` |\r\n * | `(cos(u) sin(v), sin(u) sin(v), cos(v))` | parametric, in `u` and `v` |\r\n */\r\nexport type SurfaceEquation =\r\n | { kind: \"height\"; f: CompiledExpression }\r\n | { kind: \"parametric\"; x: CompiledExpression; y: CompiledExpression; z: CompiledExpression };\r\n\r\n/** A curve through space, three parts in `t`: `(cos(t), sin(t), t / 4)`. */\r\nexport interface SpaceCurveEquation {\r\n x: CompiledExpression;\r\n y: CompiledExpression;\r\n z: CompiledExpression;\r\n}\r\n\r\n/** What each 3D form is written over, for a host's help text. */\r\nexport const EQUATION_VARIABLES_3D = {\r\n height: [\"x\", \"y\"],\r\n surface: [\"u\", \"v\"],\r\n spaceCurve: [\"t\"],\r\n} as const;\r\n\r\nconst SURFACE_NAMES: ReadonlySet<string> = new Set([\"x\", \"y\", \"z\", \"u\", \"v\"]);\r\nconst SPACE_CURVE_NAMES: ReadonlySet<string> = new Set([\"t\"]);\r\n\r\nconst surfaces = createBoundedCache<SurfaceEquation | Error>(128);\r\nconst curves = createBoundedCache<SpaceCurveEquation | Error>(128);\r\n\r\n/** The named values a surface's equation reads: every name that is not one of its variables. */\r\nexport function surfaceParams(source: string): readonly string[] {\r\n return equationNames(source).filter((name) => !SURFACE_NAMES.has(name));\r\n}\r\n\r\n/** The named values a space curve's equation reads. */\r\nexport function spaceCurveParams(source: string): readonly string[] {\r\n return equationNames(source).filter((name) => !SPACE_CURVE_NAMES.has(name));\r\n}\r\n\r\n/** `source` as a surface, or the reason it is not one. Memoised, so an unchanged equation is the identical object. */\r\nexport function parseSurface(source: string, params: readonly string[] = []): SurfaceEquation | Error {\r\n return memo(surfaces, source, params, (text) => {\r\n const compile = compiler(params);\r\n const parts = splitTuple(text);\r\n if (parts) {\r\n if (parts.length !== 3) throw new Error(\"A parametric surface has three parts: (x, y, z)\");\r\n const [x, y, z] = parts.map((part) => compile(part, EQUATION_VARIABLES_3D.surface));\r\n return { kind: \"parametric\", x, y, z };\r\n }\r\n const sides = splitTopLevel(text, \"=\");\r\n if (sides.length > 2) throw new Error(\"An equation has one '='\");\r\n if (sides.length === 2 && sides[0].trim() !== \"z\") throw new Error(\"A surface is written z = …, or as three parts (x, y, z)\");\r\n return { kind: \"height\", f: compile(sides[sides.length - 1], EQUATION_VARIABLES_3D.height) };\r\n });\r\n}\r\n\r\n/** `source` as a space curve, or the reason it is not one. */\r\nexport function parseSpaceCurve(source: string, params: readonly string[] = []): SpaceCurveEquation | Error {\r\n return memo(curves, source, params, (text) => {\r\n const compile = compiler(params);\r\n const parts = splitTuple(text);\r\n if (parts?.length !== 3) throw new Error(\"A space curve has three parts: (x, y, z)\");\r\n const [x, y, z] = parts.map((part) => compile(part, EQUATION_VARIABLES_3D.spaceCurve));\r\n return { x, y, z };\r\n });\r\n}\r\n\r\n/** Why `source` will not draw as a surface, or `null`; empty text is not an error. */\r\nexport function surfaceError(source: string): string | null {\r\n if (source.trim() === \"\") return null;\r\n const equation = parseSurface(source, surfaceParams(source));\r\n return equation instanceof Error ? equation.message : null;\r\n}\r\n\r\n/** Why `source` will not draw as a space curve, or `null`. */\r\nexport function spaceCurveError(source: string): string | null {\r\n if (source.trim() === \"\") return null;\r\n const equation = parseSpaceCurve(source, spaceCurveParams(source));\r\n return equation instanceof Error ? equation.message : null;\r\n}\r\n\r\nfunction compiler(params: readonly string[]) {\r\n return (text: string, variables: readonly string[]): CompiledExpression => {\r\n const result = compileExpressionCached(text.trim(), variables, params);\r\n if (result instanceof Error) throw result;\r\n return result;\r\n };\r\n}\r\n\r\nfunction memo<T extends object>(\r\n cache: ReturnType<typeof createBoundedCache<T | Error>>,\r\n source: string,\r\n params: readonly string[],\r\n read: (text: string) => T,\r\n): T | Error {\r\n const key = `${params.join(\",\")}|${source}`;\r\n const hit = cache.get(key);\r\n if (hit !== undefined) return hit;\r\n let result: T | Error;\r\n try {\r\n const text = source.trim();\r\n if (text === \"\") throw new Error(\"Empty equation\");\r\n result = read(text);\r\n } catch (error) {\r\n result = error instanceof Error ? error : new Error(String(error));\r\n }\r\n cache.set(key, result);\r\n return result;\r\n}\r\n\r\n/** How a host checks an equation as it is typed, and finds its named values, by the `kind` its property declares. */\r\nexport interface EquationLanguage {\r\n error(source: string): string | null;\r\n params(source: string): readonly string[];\r\n variables: readonly string[];\r\n}\r\n\r\nexport const EQUATION_KINDS: Readonly<\r\n Record<\"equation\" | \"surfaceEquation\" | \"spaceCurveEquation\" | \"fieldEquation\", EquationLanguage>\r\n> = {\r\n equation: { error: equationError, params: equationParams, variables: [...new Set(Object.values(EQUATION_VARIABLES).flat())] },\r\n surfaceEquation: {\r\n error: surfaceError,\r\n params: surfaceParams,\r\n variables: [...EQUATION_VARIABLES_3D.height, ...EQUATION_VARIABLES_3D.surface],\r\n },\r\n spaceCurveEquation: { error: spaceCurveError, params: spaceCurveParams, variables: EQUATION_VARIABLES_3D.spaceCurve },\r\n fieldEquation: { error: fieldError, params: fieldParams, variables: FIELD_VARIABLES },\r\n};\r\n", "import { Node3D, type ChildSpace3D, type Vector3 } from \"@motionscript/sdk\";\r\nimport type { Interval } from \"../kit/coords\";\r\n\r\n/**\r\n * A 3D graph's coordinates, as its axes' local space sees them. A graph is\r\n * right-handed with z up, and the scene has y up, so graph x, y and z run along\r\n * the scene's z, x and y: looked at head-on, y is to the right and z is up.\r\n */\r\nexport interface GraphSpace extends ChildSpace3D {\r\n readonly xRange: Interval;\r\n readonly yRange: Interval;\r\n readonly zRange: Interval;\r\n /** Changes exactly when the mapping does: what a mark's geometry is cached under. */\r\n readonly revision: string;\r\n /** A step from one graph point to another, as the local one: what a mark's own geometry is drawn in. */\r\n offset(x: number, y: number, z: number): Vector3;\r\n}\r\n\r\n/** The space of a box `lengths` on a side, in scene units, showing the three ranges, centred on its node. */\r\nexport function graphSpace(xRange: Interval, yRange: Interval, zRange: Interval, lengths: Vector3): GraphSpace {\r\n const ux = unit(xRange, lengths.x);\r\n const uy = unit(yRange, lengths.y);\r\n const uz = unit(zRange, lengths.z);\r\n const cx = (xRange[0] + xRange[1]) / 2;\r\n const cy = (yRange[0] + yRange[1]) / 2;\r\n const cz = (zRange[0] + zRange[1]) / 2;\r\n return {\r\n xRange,\r\n yRange,\r\n zRange,\r\n revision: [xRange, yRange, zRange, lengths.x, lengths.y, lengths.z].join(\"|\"),\r\n toLocal: (x, y, z) => ({ x: (y - cy) * uy, y: (z - cz) * uz, z: (x - cx) * ux }),\r\n offset: (x, y, z) => ({ x: y * uy, y: z * uz, z: x * ux }),\r\n };\r\n}\r\n\r\nfunction unit([min, max]: Interval, length: number): number {\r\n const span = max - min;\r\n return span > 0 ? length / span : 0;\r\n}\r\n\r\ninterface Spaced {\r\n _graphSpace(): GraphSpace;\r\n}\r\n\r\n/** The graph a 3D mark is drawn in: its nearest ancestor that has one, up to and including the viewport. */\r\nexport function spaceOf(mark: Node3D): GraphSpace | null {\r\n for (let at = mark.parent; at; at = at instanceof Node3D ? at.parent : null) {\r\n const spaced = at as Partial<Spaced>;\r\n if (typeof spaced._graphSpace === \"function\") return spaced._graphSpace();\r\n }\r\n return null;\r\n}\r\n\r\n/** A unit quaternion turning the scene's +y, the way a cylinder or a cone points, onto `direction`. */\r\nexport function aim(direction: Vector3): { x: number; y: number; z: number; w: number } {\r\n const length = Math.hypot(direction.x, direction.y, direction.z);\r\n if (!(length > 0)) return { x: 0, y: 0, z: 0, w: 1 };\r\n const dx = direction.x / length;\r\n const dy = direction.y / length;\r\n const dz = direction.z / length;\r\n // Straight down is the one turn with no single axis: any in the ground plane will do.\r\n if (dy < -1 + 1e-9) return { x: 1, y: 0, z: 0, w: 0 };\r\n const w = 1 + dy;\r\n const norm = Math.hypot(dz, dx, w);\r\n return { x: dz / norm, y: 0, z: -dx / norm, w: w / norm };\r\n}\r\n", "import { Fills, Graphics2D, Mat, Tex, type Color, type Graphics3D, type SurfaceTexture3D, type Vector3 } from \"@motionscript/sdk\";\r\nimport { createBoundedCache } from \"../kit/cache\";\r\n\r\n/** Text in a 3D graph: a camera-facing card, so a number reads square-on from wherever the scene is seen. */\r\n\r\nexport interface LabelStyle3D {\r\n /** The height of the text's em, in scene units. */\r\n size: number;\r\n color: Color;\r\n fontFamily: string;\r\n}\r\n\r\n/** The em the text is rasterized at, in buffer pixels, and the card's height around it. */\r\nconst EM = 64;\r\nconst CARD_HEIGHT = 96;\r\n\r\n// A texture's identity is its source object, so one text in one style is one source for as long as it is asked for.\r\nconst cards = createBoundedCache<{ texture: SurfaceTexture3D; width: number }>(256);\r\n\r\nfunction card(text: string, style: LabelStyle3D): { texture: SurfaceTexture3D; width: number } {\r\n const key = `${style.fontFamily}|${JSON.stringify(style.color)}|${text}`;\r\n const hit = cards.get(key);\r\n if (hit) return hit;\r\n const width = Math.min(1024, Math.max(128, Math.ceil((text.length * EM * 0.62 + EM) / 32) * 32));\r\n const source = new Graphics2D()\r\n .text({\r\n text,\r\n fontSize: EM,\r\n ...(style.fontFamily === \"\" ? {} : { fontFamily: style.fontFamily }),\r\n wrap: false,\r\n width,\r\n textAlign: \"center\",\r\n })\r\n .fill(Fills.color(style.color));\r\n const made = { texture: Tex.surface(source, { width, height: CARD_HEIGHT }), width };\r\n cards.set(key, made);\r\n return made;\r\n}\r\n\r\n/** Draw `text` centred on `at`, a local point. */\r\nexport function drawLabel3D(g3: Graphics3D, text: string, at: Vector3, style: LabelStyle3D): void {\r\n if (text === \"\" || !(style.size > 0)) return;\r\n const { texture, width } = card(text, style);\r\n const height = (style.size * CARD_HEIGHT) / EM;\r\n g3.sprite({\r\n material: Mat.sprite({ map: texture, transparent: true, depthWrite: false }),\r\n position: at,\r\n scale: [(height * width) / CARD_HEIGHT, height, 1],\r\n });\r\n}\r\n", "import {\r\n command,\r\n node,\r\n property,\r\n strokeProperty,\r\n withdraw,\r\n type Command,\r\n type CommandArgs,\r\n type NodeConfig,\r\n type PaintProps,\r\n type Stroke,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport { traceContour } from \"../kit/contour\";\r\nimport type { CoordinateMap, Interval } from \"../kit/coords\";\r\nimport type { Curve } from \"../kit/curve\";\r\nimport { equationParams, parseEquation, type Equation } from \"../kit/equation\";\r\nimport type { ExpressionScope } from \"../kit/expression\";\r\nimport { PLOT_COLOR } from \"../kit/furniture\";\r\nimport { stated } from \"../kit/geometry\";\r\nimport { Mark } from \"../kit/mark\";\r\nimport { sampleCurve, type CurveProjection } from \"../kit/sampler\";\r\nimport { lerpDomain, lerpParams, lerpSource, readSource, scopeFor, type PlotSource } from \"../kit/source\";\r\nimport { SYSTEMS } from \"../kit/placement\";\r\nimport { FILL_PAINT } from \"../kit/withdrawn\";\r\n\r\nexport interface FunctionPlotProps extends PaintProps {\r\n expression?: string | PlotSource;\r\n domain?: Interval | null;\r\n params?: ExpressionScope;\r\n}\r\n\r\nconst TAU = Math.PI * 2;\r\n\r\n/**\r\n * The curve of an equation, drawn in the coordinate system it is a child of.\r\n * How the equation is written says what it is: see `Equation`. A mark put\r\n * inside it reads it: the area under it, a tangent, a point that rides it.\r\n */\r\n@node({\r\n key: \"functionPlot\",\r\n within: SYSTEMS,\r\n closed: true,\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: true },\r\n seed: { expression: \"sin(x)\" },\r\n})\r\n@withdraw(...FILL_PAINT)\r\nexport class FunctionPlot<P extends FunctionPlotProps = FunctionPlotProps> extends Mark<P> implements Curve {\r\n @property({ default: \"\", mapper: readSource, tween: lerpSource, kind: \"equation\" })\r\n declare expression: PlotSource;\r\n\r\n /**\r\n * The span of the free variable that is drawn. Left out, a function runs the\r\n * width of its system, a polar curve one turn and a parametric one from 0 to 1.\r\n */\r\n @property({ default: null, tween: lerpDomain, kind: \"range\", defaultMin: -5, defaultMax: 5 }) declare domain: Interval | null;\r\n\r\n /**\r\n * The equation's named values: any name in it that is not a variable, a\r\n * function or a constant. One left unset is 1, and a formula can bind each\r\n * to a variable.\r\n */\r\n @property({ default: {}, tween: lerpParams }) declare params: ExpressionScope;\r\n\r\n @strokeProperty({ default: { weight: 3, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" } })\r\n declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<FunctionPlot<P>, P>) {\r\n super((props ?? {}) as NodeConfig<FunctionPlot<P>, P>);\r\n }\r\n\r\n /** Change the equation, the curve bending from the one into the other. */\r\n @command({ args: [\"expression\"] })\r\n morphTo(args: CommandArgs<{ expression: string }> & { duration: number }): Command<P> {\r\n return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** Animate the equation's named values. */\r\n @command({ args: [\"params\"] })\r\n paramsTo(args: CommandArgs<{ params: ExpressionScope }> & { duration: number }): Command<P> {\r\n return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** Animate the span that is drawn. */\r\n @command({ args: [\"domain\"] })\r\n domainTo(args: CommandArgs<{ domain: Interval | null }> & { duration: number }): Command<P> {\r\n return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /**\r\n * The curve's height at graph `x`, or `NaN` where it has none or is not a\r\n * function of `x`. What a point, a tangent or an area riding this plot reads.\r\n */\r\n valueAt(x: number): number {\r\n const { source, blend } = this.expression;\r\n const shift = this.shift();\r\n const value = this._heightOf(source, x - shift.x) + shift.y;\r\n if (!blend) return value;\r\n const from = this._heightOf(blend.from, x - shift.x) + shift.y;\r\n return from + (value - from) * blend.t;\r\n }\r\n\r\n /** The span of the free variable that is drawn: `domain`, unless a node built on this one says otherwise. */\r\n protected span(): Interval | null {\r\n return this.domain;\r\n }\r\n\r\n protected trace(map: CoordinateMap): Vector2[][] {\r\n const { area } = map;\r\n if (!Number.isFinite(area.maxX - area.minX)) return [];\r\n const { source, blend } = this.expression;\r\n const shift = this.shift();\r\n const key = [source, blend?.from, blend?.t, map.revision, this.span(), JSON.stringify(this.params), shift.x, shift.y].join(\"|\");\r\n if (key === this._key) return this._runs;\r\n this._key = key;\r\n\r\n // A curve with no parameter to walk cannot bend into another: it changes over half way.\r\n const shown = blend && blend.t < 0.5 ? blend.from : source;\r\n if (this._equation(source)?.kind === \"implicit\" || (blend && this._equation(blend.from)?.kind === \"implicit\")) {\r\n this._runs = this._contour(shown, map, shift);\r\n return this._runs;\r\n }\r\n\r\n let curve = this._curve(source, map, shift);\r\n if (curve && blend) {\r\n const from = this._curve(blend.from, map, shift);\r\n if (from) curve = between(from, curve, blend.t);\r\n }\r\n const width = area.maxX - area.minX;\r\n this._runs = curve\r\n ? sampleCurve(curve, 0, 1, area, { seeds: Math.min(512, Math.max(64, Math.round(width / 8))), minStep: 0.5 / Math.max(1, width) })\r\n : [];\r\n return this._runs;\r\n }\r\n\r\n private _key = \"\";\r\n private _runs: Vector2[][] = [];\r\n\r\n private _equation(source: string): Equation | null {\r\n const equation = parseEquation(source, equationParams(source));\r\n return equation instanceof Error ? null : equation;\r\n }\r\n\r\n private _heightOf(source: string, x: number): number {\r\n const equation = this._equation(source);\r\n if (equation?.kind !== \"function\" || equation.of !== \"x\") return NaN;\r\n return equation.f(x, 0, scopeFor(equationParams(source), this.params));\r\n }\r\n\r\n /** Where an implicit `source` holds, over what the system shows, as pixel runs. */\r\n private _contour(source: string, map: CoordinateMap, shift: Vector2): Vector2[][] {\r\n const equation = this._equation(source);\r\n if (equation?.kind !== \"implicit\") return [];\r\n const params = scopeFor(equationParams(source), this.params);\r\n const { area } = map;\r\n const cells = (pixels: number) => Math.min(CONTOUR_MAX, Math.max(8, Math.round(pixels / CONTOUR_CELL)));\r\n const { f } = equation;\r\n const runs = traceContour(\r\n (x, y) => f(x - shift.x, y - shift.y, params),\r\n map.xRange,\r\n map.yRange,\r\n cells(area.maxX - area.minX),\r\n cells(area.maxY - area.minY),\r\n );\r\n return runs.map((run) => run.map((point) => map.toPoint(point.x, point.y)));\r\n }\r\n\r\n /** `source` as a pixel curve over a parameter running 0 to 1. */\r\n private _curve(source: string, map: CoordinateMap, shift: Vector2): CurveProjection | null {\r\n const equation = this._equation(source);\r\n if (!equation || equation.kind === \"implicit\") return null;\r\n const params = scopeFor(equationParams(source), this.params);\r\n const domain = this.span();\r\n switch (equation.kind) {\r\n case \"function\": {\r\n const horizontal = equation.of === \"x\";\r\n const [lo, hi] = horizontal ? map.xRange : map.yRange;\r\n const offset = horizontal ? shift.x : shift.y;\r\n // Only what the system shows is sampled, however wide the domain.\r\n const a = Math.max(lo - offset, domain?.[0] ?? -Infinity);\r\n const b = Math.min(hi - offset, domain?.[1] ?? Infinity);\r\n if (!(b > a)) return null;\r\n const { f } = equation;\r\n return (u, out) => {\r\n const v = a + (b - a) * u;\r\n const w = f(v, 0, params);\r\n if (!Number.isFinite(w)) return false;\r\n if (horizontal) map.toPoint(v + shift.x, w + shift.y, out);\r\n else map.toPoint(w + shift.x, v + shift.y, out);\r\n return true;\r\n };\r\n }\r\n case \"polar\": {\r\n const [a, b] = domain ?? [0, TAU];\r\n const { f } = equation;\r\n return (u, out) => {\r\n const theta = a + (b - a) * u;\r\n const r = f(theta, 0, params);\r\n if (!Number.isFinite(r)) return false;\r\n map.toPoint(r * Math.cos(theta) + shift.x, r * Math.sin(theta) + shift.y, out);\r\n return true;\r\n };\r\n }\r\n case \"parametric\": {\r\n const [a, b] = domain ?? [0, 1];\r\n const { x, y } = equation;\r\n return (u, out) => {\r\n const t = a + (b - a) * u;\r\n const gx = x(t, 0, params);\r\n const gy = y(t, 0, params);\r\n if (!Number.isFinite(gx) || !Number.isFinite(gy)) return false;\r\n map.toPoint(gx + shift.x, gy + shift.y, out);\r\n return true;\r\n };\r\n }\r\n }\r\n }\r\n}\r\n\r\n// Roughly one cell of the contour's grid to this many pixels, each way.\r\nconst CONTOUR_CELL = 5;\r\nconst CONTOUR_MAX = 220;\r\n\r\n// Two curves blended point for point along their parameters, in pixels, so any\r\n// kind bends into any other.\r\nfunction between(from: CurveProjection, to: CurveProjection, t: number): CurveProjection {\r\n const a: Vector2 = { x: 0, y: 0 };\r\n return (u, out) => {\r\n if (!from(u, a) || !to(u, out)) return false;\r\n out.x = a.x + (out.x - a.x) * t;\r\n out.y = a.y + (out.y - a.y) * t;\r\n return true;\r\n };\r\n}\r\n", "import type { Vector2 } from \"@motionscript/sdk\";\r\n\r\n/**\r\n * The lines along which a function of two variables is zero, over a box of\r\n * graph values: marching squares, its crossings placed by linear interpolation\r\n * and joined end to end into runs. Points are graph coordinates.\r\n */\r\nexport function traceContour(\r\n f: (x: number, y: number) => number,\r\n [x0, x1]: readonly [number, number],\r\n [y0, y1]: readonly [number, number],\r\n columns: number,\r\n rows: number,\r\n): Vector2[][] {\r\n if (!(x1 > x0) || !(y1 > y0) || columns < 1 || rows < 1) return [];\r\n const dx = (x1 - x0) / columns;\r\n const dy = (y1 - y0) / rows;\r\n const stride = columns + 1;\r\n const values = new Float64Array(stride * (rows + 1));\r\n for (let j = 0; j <= rows; j++) {\r\n for (let i = 0; i <= columns; i++) values[j * stride + i] = f(x0 + i * dx, y0 + j * dy);\r\n }\r\n\r\n // A crossing lives on a grid edge, which is its name: two cells sharing the edge share the point.\r\n const points = new Map<number, Vector2>();\r\n const edgeCount = stride * (rows + 1);\r\n const crossing = (i: number, j: number, vertical: boolean): number | null => {\r\n const a = values[j * stride + i];\r\n const b = vertical ? values[(j + 1) * stride + i] : values[j * stride + i + 1];\r\n if (!Number.isFinite(a) || !Number.isFinite(b) || a < 0 === b < 0) return null;\r\n const key = (vertical ? edgeCount : 0) + j * stride + i;\r\n if (!points.has(key)) {\r\n const t = a / (a - b);\r\n points.set(key, vertical ? { x: x0 + i * dx, y: y0 + (j + t) * dy } : { x: x0 + (i + t) * dx, y: y0 + j * dy });\r\n }\r\n return key;\r\n };\r\n\r\n const next = new Map<number, number[]>();\r\n const join = (a: number | null, b: number | null): void => {\r\n if (a === null || b === null) return;\r\n (next.get(a) ?? next.set(a, []).get(a)!).push(b);\r\n (next.get(b) ?? next.set(b, []).get(b)!).push(a);\r\n };\r\n for (let j = 0; j < rows; j++) {\r\n for (let i = 0; i < columns; i++) {\r\n const bottom = crossing(i, j, false);\r\n const top = crossing(i, j + 1, false);\r\n const left = crossing(i, j, true);\r\n const right = crossing(i + 1, j, true);\r\n const found = [bottom, right, top, left].filter((edge) => edge !== null);\r\n if (found.length === 2) join(found[0], found[1]);\r\n else if (found.length === 4) {\r\n // A saddle: the centre's sign says which pairs of edges the curve joins.\r\n const centre = f(x0 + (i + 0.5) * dx, y0 + (j + 0.5) * dy);\r\n const corner = values[j * stride + i];\r\n if (centre < 0 === corner < 0) {\r\n join(bottom, right);\r\n join(top, left);\r\n } else {\r\n join(bottom, left);\r\n join(top, right);\r\n }\r\n }\r\n }\r\n }\r\n\r\n const runs: Vector2[][] = [];\r\n const used = new Set<number>();\r\n const walk = (from: number): Vector2[] => {\r\n const run: Vector2[] = [points.get(from)!];\r\n used.add(from);\r\n let at = from;\r\n for (;;) {\r\n const onward = (next.get(at) ?? []).find((key) => !used.has(key));\r\n if (onward === undefined) break;\r\n used.add(onward);\r\n run.push(points.get(onward)!);\r\n at = onward;\r\n }\r\n return run;\r\n };\r\n // Open runs first, from their ends, so each is one run and not two halves.\r\n for (const [key, links] of next) {\r\n if (links.length === 1 && !used.has(key)) runs.push(walk(key));\r\n }\r\n for (const key of next.keys()) {\r\n if (used.has(key)) continue;\r\n const run = walk(key);\r\n run.push(run[0]);\r\n runs.push(run);\r\n }\r\n return runs.filter((run) => run.length > 1);\r\n}\r\n", "/**\r\n * The coordinate systems a 2D plot or mark goes inside, for a node's `within`.\r\n * A number plane is built on `axes2d`, so naming that covers it.\r\n */\r\nexport const SYSTEMS: readonly string[] = [\"axes2d\", \"numberLine\", \"polarPlane\"];\r\n\r\n/** The systems, and a plot: where a mark that may ride a curve goes. */\r\nexport const SYSTEMS_AND_PLOT: readonly string[] = [...SYSTEMS, \"functionPlot\"];\r\n", "import {\r\n command,\r\n Graphics2D,\r\n property,\r\n withdraw,\r\n type Command,\r\n type CommandArgs,\r\n type Fill,\r\n type FillResolved,\r\n type PaintProps,\r\n type RenderContext2D,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport type { CoordinateMap } from \"./coords\";\r\nimport type { ExpressionScope } from \"./expression\";\r\nimport { fieldParams, parseField } from \"./field\";\r\nimport { boundsOfRuns, runsToPath, stated } from \"./geometry\";\r\nimport { Mark } from \"./mark\";\r\nimport { fillAt, lerpFillScale, readFillScale } from \"./scale\";\r\nimport { lerpParams, lerpSource, readSource, scopeFor, type PlotSource } from \"./source\";\r\nimport { FILL_PAINT, OUTLINE_TRIM } from \"./withdrawn\";\r\n\r\nexport interface FieldProps extends PaintProps {\r\n expression?: string | PlotSource;\r\n params?: ExpressionScope;\r\n strengthFills?: Fill[];\r\n maxMagnitude?: number;\r\n}\r\n\r\n/** A field's vector at a graph point, written into `out`; `false` where it has none. */\r\nexport type FieldSampler = (x: number, y: number, out: Vector2) => boolean;\r\n\r\n/** One thing a field draws, and how strong the field is there: what it is coloured by. */\r\nexport interface FieldStroke {\r\n runs: Vector2[][];\r\n magnitude: number;\r\n}\r\n\r\n/** How many shades the strength fills are drawn in: each is one path. */\r\nconst SHADES = 12;\r\n\r\n/**\r\n * A mark drawn from a vector field, `(P(x, y), Q(x, y))`: arrows, or the lines\r\n * that follow it, all in one stroke. Without strength fills it is one path in\r\n * the stroke's paint; with them, what it draws is sorted by the field's\r\n * strength into a few shades.\r\n */\r\n@withdraw(...FILL_PAINT, ...OUTLINE_TRIM)\r\nexport abstract class FieldMark<P extends FieldProps = FieldProps> extends Mark<P> {\r\n @property({ default: \"\", mapper: readSource, tween: lerpSource, kind: \"fieldEquation\" })\r\n declare expression: PlotSource;\r\n\r\n /** The equation's named values: any name in it that is not `x`, `y`, a function or a constant. */\r\n @property({ default: {}, tween: lerpParams }) declare params: ExpressionScope;\r\n\r\n /** Paints by the field's strength, weakest first. Empty draws everything in the stroke's own paint. */\r\n @property({ default: [], mapper: readFillScale, tween: lerpFillScale, kind: \"vector\" }) declare strengthFills: Fill[];\r\n /** The strength the last paint stands for; zero takes the strongest the field is where it is drawn. */\r\n @property({ default: 0, min: 0, step: 0.1 }) declare maxMagnitude: number;\r\n\r\n /** Change the field, each vector turning from the one into the other. */\r\n @command({ args: [\"expression\"] })\r\n morphTo(args: CommandArgs<{ expression: string }> & { duration: number }): Command<P> {\r\n return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** Animate the equation's named values. */\r\n @command({ args: [\"params\"] })\r\n paramsTo(args: CommandArgs<{ params: ExpressionScope }> & { duration: number }): Command<P> {\r\n return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** What is drawn of `field` through `map`. */\r\n protected abstract strokes(map: CoordinateMap, field: FieldSampler): FieldStroke[];\r\n\r\n /** The props of its own that change what {@link strokes} returns. */\r\n protected abstract own(): string;\r\n\r\n protected trace(map: CoordinateMap): Vector2[][] {\r\n const { area } = map;\r\n if (!Number.isFinite(area.maxX - area.minX)) return [];\r\n const { source, blend } = this.expression;\r\n const shift = this.shift();\r\n const key = [source, blend?.from, blend?.t, map.revision, JSON.stringify(this.params), shift.x, shift.y, this.own()].join(\"|\");\r\n if (key !== this._key) {\r\n this._key = key;\r\n const field = this._sampler(shift);\r\n this._drawn = field ? this.strokes(map, field) : [];\r\n this._runs = this._drawn.flatMap((stroke) => stroke.runs);\r\n }\r\n return this._runs;\r\n }\r\n\r\n protected override renderInk(ctx: RenderContext2D): void {\r\n const scale = this.strengthFills as unknown as FillResolved[][];\r\n const stroke = this.stroke as StrokeResolved[];\r\n const ink = scale.length > 0 && stroke.length > 0 ? boundsOfRuns(this._runs) : null;\r\n if (!ink) {\r\n super.renderInk(ctx);\r\n return;\r\n }\r\n const top = this.maxMagnitude > 0 ? this.maxMagnitude : this._drawn.reduce((most, drawn) => Math.max(most, drawn.magnitude), 0);\r\n const shades: Vector2[][][] = Array.from({ length: SHADES }, () => []);\r\n for (const drawn of this._drawn) {\r\n const share = top > 0 ? Math.min(1, drawn.magnitude / top) : 0;\r\n shades[Math.min(SHADES - 1, Math.floor(share * SHADES))].push(...drawn.runs);\r\n }\r\n shades.forEach((runs, index) => {\r\n if (runs.length === 0) return;\r\n const fill = fillAt(scale, (index + 0.5) / SHADES);\r\n ctx.draw(\r\n new Graphics2D()\r\n .path({ data: runsToPath(runs), centerBounds: [ink.minX, ink.minY, ink.maxX, ink.maxY], start: this.start, end: this.end })\r\n .shadow(this.shadow)\r\n .stroke(stroke.map((layer) => ({ ...layer, fill }))),\r\n );\r\n });\r\n }\r\n\r\n private _key = \"\";\r\n private _drawn: FieldStroke[] = [];\r\n private _runs: Vector2[][] = [];\r\n\r\n /** The field at a graph point, measured from this mark's own shift, mid-morph a blend of two. */\r\n private _sampler(shift: Vector2): FieldSampler | null {\r\n const { source, blend } = this.expression;\r\n const to = this._field(source, shift);\r\n if (!to || !blend) return to;\r\n const from = this._field(blend.from, shift);\r\n if (!from) return to;\r\n const start: Vector2 = { x: 0, y: 0 };\r\n return (x, y, out) => {\r\n if (!from(x, y, start) || !to(x, y, out)) return false;\r\n out.x = start.x + (out.x - start.x) * blend.t;\r\n out.y = start.y + (out.y - start.y) * blend.t;\r\n return true;\r\n };\r\n }\r\n\r\n private _field(source: string, shift: Vector2): FieldSampler | null {\r\n const names = fieldParams(source);\r\n const field = parseField(source, names);\r\n if (field instanceof Error) return null;\r\n const params = scopeFor(names, this.params);\r\n const { x, y } = field;\r\n return (gx, gy, out) => {\r\n const vx = x(gx - shift.x, gy - shift.y, params);\r\n const vy = y(gx - shift.x, gy - shift.y, params);\r\n out.x = vx;\r\n out.y = vy;\r\n return Number.isFinite(vx) && Number.isFinite(vy);\r\n };\r\n }\r\n}\r\n", "import { colorOps, fillOps, type Color, type Fill, type FillResolved, type NormalizedColor } from \"@motionscript/sdk\";\r\nimport { clamp } from \"./geometry\";\r\n\r\n/** A run of colours a value is read off, lowest first: a surface's height, a field's strength. */\r\n\r\nexport function readScale(value: readonly Color[] | undefined): NormalizedColor[] {\r\n return (value ?? []).map((color) => colorOps.resolve(color));\r\n}\r\n\r\nexport function lerpScale(from: NormalizedColor[], to: NormalizedColor[], t: number): NormalizedColor[] {\r\n if (from.length !== to.length) return t < 1 ? from : to;\r\n return to.map((color, index) => colorOps.lerp(from[index], color, t));\r\n}\r\n\r\n/** The colour `share` of the way along `scale`, 0 to 1. */\r\nexport function colorAt(scale: readonly NormalizedColor[], share: number): NormalizedColor {\r\n if (scale.length === 1) return scale[0];\r\n const at = clamp(share, 0, 1) * (scale.length - 1);\r\n const index = Math.min(scale.length - 2, Math.floor(at));\r\n return colorOps.lerp(scale[index], scale[index + 1], at - index);\r\n}\r\n\r\n/** A run of paints a value is read off, lowest first: a field's strength. Every entry is kept as written. */\r\nexport function readFillScale(value: readonly Fill[] | undefined): FillResolved[][] {\r\n return (Array.isArray(value) ? value : []).map((fill) => fillOps.resolve(fill ?? []));\r\n}\r\n\r\nexport function lerpFillScale(from: FillResolved[][], to: FillResolved[][], t: number): FillResolved[][] {\r\n if (from.length !== to.length) return t < 1 ? from : to;\r\n return to.map((fill, index) => fillOps.lerp(from[index], fill, t));\r\n}\r\n\r\n/** The paint `share` of the way along `scale`, 0 to 1. */\r\nexport function fillAt(scale: readonly FillResolved[][], share: number): FillResolved[] {\r\n if (scale.length === 1) return scale[0];\r\n const at = clamp(share, 0, 1) * (scale.length - 1);\r\n const index = Math.min(scale.length - 2, Math.floor(at));\r\n return fillOps.lerp(scale[index], scale[index + 1], at - index);\r\n}\r\n", "import type { PathCommand, Vector2 } from \"@motionscript/sdk\";\r\nimport { add, between, heading } from \"./follow\";\r\n\r\n/** How far a quarter circle's control points sit along its tangents, as a share of its radius. */\r\nconst QUARTER = 0.5523;\r\n\r\n/**\r\n * A curly brace from `from` to `to`, bulging toward `out` (a unit vector) and\r\n * `reach` deep at its tip: what a brace node draws, and a sample space beside\r\n * its parts. Path commands, y-up.\r\n */\r\nexport function braceOutline(from: Vector2, to: Vector2, out: Vector2, reach: number): PathCommand[] {\r\n const { unit, length } = heading(from, to);\r\n if (length === 0) return [];\r\n const r = Math.min(reach / 2, length / 4);\r\n const mid = between(from, to);\r\n const lift = (p: Vector2, k: number) => add(p, out, k * r);\r\n const along = (p: Vector2, k: number) => add(p, unit, k * r);\r\n const h = QUARTER;\r\n const curve = (c1: Vector2, c2: Vector2, end: Vector2): PathCommand => ({\r\n type: \"C\", x1: c1.x, y1: c1.y, x2: c2.x, y2: c2.y, x: end.x, y: end.y,\r\n });\r\n const a = lift(along(from, 1), 1);\r\n const b = lift(along(mid, -1), 1);\r\n const tip = lift(mid, 2);\r\n const c = lift(along(mid, 1), 1);\r\n const d = lift(along(to, -1), 1);\r\n return [\r\n { type: \"M\", x: from.x, y: from.y },\r\n curve(lift(from, h), lift(along(from, 1 - h), 1), a),\r\n { type: \"L\", x: b.x, y: b.y },\r\n curve(lift(along(mid, -1 + h), 1), lift(mid, 2 - h), tip),\r\n curve(lift(mid, 2 - h), lift(along(mid, 1 - h), 1), c),\r\n { type: \"L\", x: d.x, y: d.y },\r\n curve(lift(along(to, -1 + h), 1), lift(to, h), to),\r\n ];\r\n}\r\n", "import type { Vector2 } from \"@motionscript/sdk\";\r\n\r\n/** Where a graph's vertices are placed, inside a square from -1 to 1 each way, y up. */\r\n\r\nexport type GraphLayout = \"circular\" | \"spring\" | \"tree\" | \"grid\";\r\n\r\nexport const GRAPH_LAYOUTS: readonly GraphLayout[] = [\"circular\", \"spring\", \"tree\", \"grid\"];\r\n\r\nexport interface GraphEdge {\r\n from: string;\r\n to: string;\r\n}\r\n\r\n/** Each vertex's place under `layout`, by name. */\r\nexport function layOut(layout: GraphLayout, vertices: readonly string[], edges: readonly GraphEdge[], root: string): Map<string, Vector2> {\r\n const n = vertices.length;\r\n if (n === 0) return new Map();\r\n if (n === 1) return new Map([[vertices[0], { x: 0, y: 0 }]]);\r\n switch (layout) {\r\n case \"grid\":\r\n return grid(vertices);\r\n case \"tree\":\r\n return fill(tree(vertices, edges, root));\r\n case \"spring\":\r\n return fill(spring(vertices, edges));\r\n default:\r\n return circular(vertices);\r\n }\r\n}\r\n\r\nfunction circular(vertices: readonly string[]): Map<string, Vector2> {\r\n const n = vertices.length;\r\n // The first at the top, the rest clockwise, as a clock is read.\r\n return new Map(vertices.map((name, i) => {\r\n const angle = Math.PI / 2 - (2 * Math.PI * i) / n;\r\n return [name, { x: Math.cos(angle), y: Math.sin(angle) }];\r\n }));\r\n}\r\n\r\nfunction grid(vertices: readonly string[]): Map<string, Vector2> {\r\n const columns = Math.ceil(Math.sqrt(vertices.length));\r\n const rows = Math.ceil(vertices.length / columns);\r\n const at = (i: number, count: number) => (count === 1 ? 0 : -1 + (2 * i) / (count - 1));\r\n return new Map(vertices.map((name, i) => [name, { x: at(i % columns, columns), y: -at(Math.floor(i / columns), rows) }]));\r\n}\r\n\r\nfunction neighbours(vertices: readonly string[], edges: readonly GraphEdge[]): Map<string, string[]> {\r\n const near = new Map(vertices.map((name) => [name, [] as string[]]));\r\n for (const { from, to } of edges) {\r\n if (from === to || !near.has(from) || !near.has(to)) continue;\r\n near.get(from)!.push(to);\r\n near.get(to)!.push(from);\r\n }\r\n return near;\r\n}\r\n\r\n/** Levels down from `root`, and across by the leaves under each, every component its own tree beside the last. */\r\nfunction tree(vertices: readonly string[], edges: readonly GraphEdge[], root: string): Map<string, Vector2> {\r\n const near = neighbours(vertices, edges);\r\n const placed = new Map<string, Vector2>();\r\n let column = 0;\r\n const visit = (name: string, depth: number, seen: Set<string>): number => {\r\n seen.add(name);\r\n const children = near.get(name)!.filter((next) => !seen.has(next));\r\n for (const child of children) seen.add(child);\r\n if (children.length === 0) {\r\n placed.set(name, { x: column++, y: -depth });\r\n return placed.get(name)!.x;\r\n }\r\n const xs = children.map((child) => visit(child, depth + 1, seen));\r\n const x = (xs[0] + xs[xs.length - 1]) / 2;\r\n placed.set(name, { x, y: -depth });\r\n return x;\r\n };\r\n const seen = new Set<string>();\r\n const first = near.has(root) ? root : vertices[0];\r\n for (const start of [first, ...vertices]) if (!seen.has(start)) visit(start, 0, seen);\r\n return placed;\r\n}\r\n\r\n/** Edges pull and every pair pushes, from the circle, for a fixed number of cooling steps: the same answer every time. */\r\nfunction spring(vertices: readonly string[], edges: readonly GraphEdge[]): Map<string, Vector2> {\r\n const n = vertices.length;\r\n const index = new Map(vertices.map((name, i) => [name, i]));\r\n const start = circular(vertices);\r\n const x = vertices.map((name) => start.get(name)!.x);\r\n const y = vertices.map((name) => start.get(name)!.y);\r\n const links = edges.flatMap(({ from, to }) => {\r\n const a = index.get(from);\r\n const b = index.get(to);\r\n return a === undefined || b === undefined || a === b ? [] : [[a, b] as const];\r\n });\r\n const k = Math.sqrt(4 / n);\r\n const steps = 160;\r\n for (let step = 0; step < steps; step++) {\r\n const dx = new Float64Array(n);\r\n const dy = new Float64Array(n);\r\n for (let i = 0; i < n; i++) {\r\n for (let j = i + 1; j < n; j++) {\r\n let ex = x[i] - x[j];\r\n let ey = y[i] - y[j];\r\n let d = Math.hypot(ex, ey);\r\n // Two on one spot are parted along a fixed, if arbitrary, line.\r\n if (d < 1e-6) [ex, ey, d] = [1e-3 * (i - j), 1e-3, 1e-3];\r\n const push = (k * k) / d;\r\n dx[i] += (ex / d) * push;\r\n dy[i] += (ey / d) * push;\r\n dx[j] -= (ex / d) * push;\r\n dy[j] -= (ey / d) * push;\r\n }\r\n }\r\n for (const [a, b] of links) {\r\n const ex = x[a] - x[b];\r\n const ey = y[a] - y[b];\r\n const d = Math.max(Math.hypot(ex, ey), 1e-6);\r\n const pull = (d * d) / k;\r\n dx[a] -= (ex / d) * pull;\r\n dy[a] -= (ey / d) * pull;\r\n dx[b] += (ex / d) * pull;\r\n dy[b] += (ey / d) * pull;\r\n }\r\n const limit = 0.12 * (1 - step / steps);\r\n for (let i = 0; i < n; i++) {\r\n const d = Math.hypot(dx[i], dy[i]);\r\n if (d > 0) {\r\n x[i] += (dx[i] / d) * Math.min(d, limit);\r\n y[i] += (dy[i] / d) * Math.min(d, limit);\r\n }\r\n }\r\n }\r\n return new Map(vertices.map((name, i) => [name, { x: x[i], y: y[i] }]));\r\n}\r\n\r\n/** `placed` stretched to reach -1 and 1 on each axis it spreads along, and centred on the one it does not. */\r\nfunction fill(placed: Map<string, Vector2>): Map<string, Vector2> {\r\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\r\n for (const p of placed.values()) {\r\n minX = Math.min(minX, p.x);\r\n maxX = Math.max(maxX, p.x);\r\n minY = Math.min(minY, p.y);\r\n maxY = Math.max(maxY, p.y);\r\n }\r\n const scale = (v: number, lo: number, hi: number) => (hi - lo < 1e-9 ? 0 : -1 + (2 * (v - lo)) / (hi - lo));\r\n return new Map([...placed].map(([name, p]) => [name, { x: scale(p.x, minX, maxX), y: scale(p.y, minY, maxY) }]));\r\n}\r\n"],
5
+ "mappings": "uFAAA,OACI,QAAAA,GACA,WAAAC,GACA,cAAAC,GACA,aAAAC,GACA,aAAAC,OAWG,oBChBP,OACI,WAAAC,OAOG,oBASP,SAASC,GAAWC,EAAY,CAC5B,OAAO,OAAQA,EAA2B,UAAa,UAC3D,CAOA,SAASC,GAASD,EAAY,CAC1B,OAAO,OAAQA,EAAyB,UAAa,UACzD,CASM,SAAUE,EACZC,EACAC,EACAC,EACAC,EACAC,EAAuB,CAEvB,IAAMC,EAAS,IAAI,QACbC,EAAmB,CAAA,EACzB,QAAWC,KAASP,EAAU,CAC1B,GAAI,CAACF,GAASS,CAAK,EAAG,CAClBD,EAAO,KAAKC,CAAK,EACjB,QACJ,CACA,IAAMC,EAAMD,EAAM,SAASN,CAAG,EACxBQ,EAAKD,GAAOA,EAAI,KAAOA,EAAI,MAAQ,EAAIN,EAAO,EAC9CQ,EAAKF,GAAOA,EAAI,KAAOA,EAAI,MAAQ,EAAIN,EAAO,EACpDK,EAAM,OACF,CAAE,EAAGE,EAAKP,EAAO,EAAG,EAAGA,EAAO,EAAIQ,EAAI,MAAOF,EAAMA,EAAI,KAAOA,EAAI,KAAO,EAAG,OAAQA,EAAMA,EAAI,KAAOA,EAAI,KAAO,CAAC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AG,EAAGG,EAAMD,EAAE,EAAGH,EAAME,CAAI,CAAC,CAAE,CAAC,CAAC,CACnH",
6
+ "names": ["Clip", "flowOps", "Graphics2D", "insetsOps", "PaintNode", "flowOps", "isAnchored", "node", "isTraced", "placeOnMap", "children", "map", "origin", "room", "scope", "planes", "others", "child", "ink", "cx", "cy", "markPlane", "sizes", "i", "pointPlane", "openPlane", "x", "y", "at", "point", "anchored", "none", "NO_CONTENT", "CENTRE", "CoordinateSystem", "PaintNode", "constraints", "flowOps", "rect", "scope", "map", "inner", "insetsOps", "placeOnMap", "child", "openPlane", "r", "Graphics2D", "ctx", "clip", "part", "minX", "minY", "maxX", "maxY", "Clip", "colorProperty", "command", "Graphics2D", "node", "property", "strokeProperty", "resolveInterval", "range", "scaling", "min", "max", "axisScale", "lo", "hi", "from", "k", "v", "p", "cartesianMap", "xRange", "yRange", "area", "xScaling", "yScaling", "x", "y", "gx", "gy", "out", "px", "py", "UNBOUNDED", "PIXEL_MAP", "IDENTITY_MATRIX", "readMatrix", "value", "previous", "flat", "entry", "lerpMatrix", "to", "t", "i", "isIdentityMatrix", "a", "b", "c", "d", "REACH", "reach", "middle", "half", "transformedMap", "base", "matrix", "det", "back", "u", "xReach", "yReach", "corner", "minX", "minY", "maxX", "maxY", "warpedMap", "warp", "key", "bend", "at", "dx", "dy", "H", "target", "ex", "ey", "j00", "j10", "j01", "j11", "widened", "WARP_MARGIN", "margin", "CURVED_STEPS", "lineThrough", "map", "x0", "y0", "x1", "y1", "run", "runsToPath", "runs", "closed", "out", "run", "i", "boundsOfRuns", "minX", "minY", "maxX", "maxY", "p", "inflate", "area", "margin", "clamp", "value", "min", "max", "stated", "data", "key", "niceStep", "MAX_TICKS", "AUTO_SPACING", "ticksFor", "range", "step", "length", "scaling", "min", "max", "decades", "span", "chosen", "multiplesWithin", "values", "k", "first", "count", "out", "i", "decadeOf", "value", "formatTick", "decade", "trimExponent", "digits", "decimals", "decimalsOf", "text", "d", "scaled", "mantissa", "exponent", "Fills", "Graphics2D", "toPathString", "AXIS_COLOR", "PLOT_COLOR", "withoutTips", "stroke", "layer", "LABEL_BOX_EM", "FORMULA", "declareFormulas", "assets", "texts", "text", "MATHJAX_LOADER", "loadMathJax", "drawLabels", "labels", "style", "out", "fill", "Fills", "Graphics2D", "width", "written", "label", "formula", "glyphs", "typeset", "glyph", "at", "align", "source", "fontSize", "buildLatexPath", "error", "LatexNotLoaded", "minX", "minY", "maxX", "maxY", "dx", "frame", "token", "toPathString", "drawn", "u", "start", "end", "along", "from", "to", "dy", "length", "lerpInterval", "t", "readInterval", "value", "previous", "min", "max", "Axes2d", "CoordinateSystem", "props", "args", "stated", "assets", "declareFormulas", "area", "xRange", "resolveInterval", "yRange", "width", "span", "centre", "cartesianMap", "map", "stroke", "start", "end", "x", "y", "parts", "Graphics2D", "half", "gap", "tickMarks", "labels", "ticked", "mark", "axis", "horizontal", "value", "at", "drawn", "along", "formatTick", "withoutTips", "drawLabels", "_map", "_x", "_y", "xMin", "xMax", "yMin", "yMax", "crossX", "clamp", "crossY", "xFrom", "xTo", "yFrom", "yTo", "lineThrough", "ticksFor", "__decorate", "property", "readInterval", "lerpInterval", "colorProperty", "AXIS_COLOR", "strokeProperty", "command", "node", "Graphics2D", "PaintNode", "Mark", "PaintNode", "NO_SHIFT", "point", "shift", "at", "centre", "ink", "PIXEL_MAP", "Graphics2D", "ctx", "rect", "scope", "children", "room", "placeOnMap", "child", "openPlane", "map", "inSystem", "runs", "runsToPath", "boundsOfRuns", "expressionOps", "UNARY", "NARY", "a", "b", "CONSTANTS", "MATH_DIALECT", "name", "arity", "expressionVocabulary", "variables", "compileExpression", "source", "params", "emit", "expressionOps", "node", "value", "slot", "_a", "_b", "scope", "operand", "l", "r", "s", "args", "arg", "unary", "x", "fn", "y", "compiled", "createBoundedCache", "compileExpressionCached", "key", "hit", "result", "error", "expressionOps", "EQUATION_VARIABLES", "parsed", "createBoundedCache", "parseEquation", "source", "params", "key", "hit", "result", "read", "error", "equationError", "equation", "equationParams", "VARIABLE_NAMES", "named", "equationNames", "names", "text", "part", "splitTuple", "splitTopLevel", "collectNames", "expressionOps", "MATH_DIALECT", "name", "node", "into", "arg", "compile", "variables", "compileExpressionCached", "pair", "sides", "left", "right", "subject", "implicit", "l", "r", "x", "y", "scope", "of", "depth", "i", "parts", "separator", "from", "c", "readSource", "value", "lerpSource", "from", "to", "t", "lerpDomain", "UNSET_PARAM", "lerpParams", "out", "name", "start", "scopeFor", "names", "params", "filled", "revisionOf", "key", "hash", "i", "arena", "arenaMark", "takeSample", "slot", "blank", "scratch", "sampleCurve", "project", "t0", "t1", "clip", "seeds", "minStep", "pen", "CurvePen", "spent", "write", "t", "defined", "ok", "clampCoord", "at", "edgeOf", "from", "to", "inside", "outsideT", "i", "offFrame", "midT", "mid", "settled", "emit", "a", "m", "b", "floored", "diverges", "edge", "refine", "depth", "flat", "count", "step", "ends", "previous", "next", "dx", "dy", "length", "turn", "sample", "value", "segment", "clipSegment", "start", "end", "samePoint", "point", "x", "y", "ax", "ay", "bx", "by", "edges", "p", "q", "r", "findNode2D", "curveNamed", "from", "id", "found", "curveOf", "mark", "on", "at", "command", "findNode2D", "frameIn", "Graphics2D", "PaintNode", "pathOps", "property", "withdraw", "isParted", "node", "followed", "mark", "on", "findNode2D", "at", "quadOf", "target", "box", "frame", "frameIn", "turn", "cos", "sin", "place", "x", "y", "w", "h", "lerpQuad", "a", "b", "t", "from", "i", "restOf", "part", "occurrence", "lerpRetarget", "to", "OWN_FRAME", "FollowMark", "PaintNode", "args", "next", "held", "state", "data", "Graphics2D", "ink", "pathOps", "quad", "__decorate", "property", "command", "withdraw", "FILL_PAINT", "add", "a", "b", "k", "between", "t", "heading", "dx", "dy", "length", "grown", "quad", "by", "tl", "tr", "br", "bl", "across", "up", "FIELD_VARIABLES", "NAMES", "fields", "createBoundedCache", "fieldParams", "source", "equationNames", "name", "parseField", "params", "key", "hit", "result", "text", "parts", "splitTuple", "x", "y", "part", "compiled", "compileExpressionCached", "error", "fieldError", "field", "EQUATION_VARIABLES_3D", "SURFACE_NAMES", "SPACE_CURVE_NAMES", "surfaces", "createBoundedCache", "curves", "surfaceParams", "source", "equationNames", "name", "spaceCurveParams", "parseSurface", "params", "memo", "text", "compile", "compiler", "parts", "splitTuple", "x", "y", "z", "part", "sides", "splitTopLevel", "parseSpaceCurve", "surfaceError", "equation", "spaceCurveError", "variables", "result", "compileExpressionCached", "cache", "read", "key", "hit", "error", "EQUATION_KINDS", "equationError", "equationParams", "EQUATION_VARIABLES", "fieldError", "fieldParams", "FIELD_VARIABLES", "Node3D", "graphSpace", "xRange", "yRange", "zRange", "lengths", "ux", "unit", "uy", "uz", "cx", "cy", "cz", "x", "y", "z", "min", "max", "length", "span", "spaceOf", "mark", "at", "spaced", "aim", "direction", "dx", "dy", "dz", "w", "norm", "Fills", "Graphics2D", "Mat", "Tex", "EM", "CARD_HEIGHT", "cards", "createBoundedCache", "card", "text", "style", "key", "hit", "width", "source", "Graphics2D", "Fills", "made", "Tex", "drawLabel3D", "g3", "at", "texture", "height", "Mat", "command", "node", "property", "strokeProperty", "withdraw", "traceContour", "f", "x0", "x1", "y0", "y1", "columns", "rows", "dx", "dy", "stride", "values", "j", "i", "points", "edgeCount", "crossing", "vertical", "a", "b", "key", "t", "next", "join", "bottom", "top", "left", "right", "found", "edge", "centre", "corner", "runs", "used", "walk", "from", "run", "at", "onward", "links", "SYSTEMS", "SYSTEMS_AND_PLOT", "TAU", "FunctionPlot", "Mark", "props", "args", "stated", "x", "source", "blend", "shift", "value", "from", "map", "area", "key", "shown", "curve", "between", "width", "sampleCurve", "equation", "parseEquation", "equationParams", "scopeFor", "params", "cells", "pixels", "CONTOUR_MAX", "CONTOUR_CELL", "f", "traceContour", "y", "run", "point", "domain", "horizontal", "lo", "hi", "offset", "a", "b", "u", "out", "v", "w", "theta", "r", "t", "gx", "gy", "__decorate", "property", "readSource", "lerpSource", "lerpDomain", "lerpParams", "strokeProperty", "PLOT_COLOR", "command", "node", "SYSTEMS", "withdraw", "FILL_PAINT", "CONTOUR_CELL", "CONTOUR_MAX", "between", "from", "to", "t", "a", "u", "out", "command", "Graphics2D", "property", "withdraw", "colorOps", "fillOps", "readScale", "value", "color", "colorOps", "lerpScale", "from", "to", "t", "index", "colorAt", "scale", "share", "at", "clamp", "readFillScale", "fill", "fillOps", "lerpFillScale", "fillAt", "SHADES", "FieldMark", "Mark", "args", "stated", "map", "area", "source", "blend", "shift", "key", "field", "stroke", "ctx", "scale", "ink", "boundsOfRuns", "top", "most", "drawn", "shades", "share", "runs", "index", "fill", "fillAt", "Graphics2D", "runsToPath", "layer", "to", "from", "start", "x", "y", "out", "names", "fieldParams", "parseField", "params", "scopeFor", "gx", "gy", "vx", "vy", "__decorate", "property", "readSource", "lerpSource", "lerpParams", "readFillScale", "lerpFillScale", "command", "withdraw", "FILL_PAINT", "OUTLINE_TRIM", "QUARTER", "braceOutline", "from", "to", "out", "reach", "unit", "length", "heading", "r", "mid", "between", "lift", "k", "add", "along", "h", "curve", "c1", "c2", "end", "a", "b", "tip", "c", "d", "GRAPH_LAYOUTS", "layOut", "layout", "vertices", "edges", "root", "n", "grid", "fill", "tree", "spring", "circular", "name", "i", "angle", "columns", "rows", "at", "count", "neighbours", "near", "from", "to", "placed", "column", "visit", "depth", "seen", "children", "next", "child", "xs", "x", "first", "start", "index", "y", "links", "a", "b", "k", "steps", "step", "dx", "dy", "j", "ex", "ey", "d", "push", "pull", "limit", "minX", "minY", "maxX", "maxY", "p", "scale", "v", "lo", "hi"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{s as d}from"./chunk-WL4KEX7Y.js";import{command as p,node as b,property as f}from"@motionscript/sdk";var u=function(n,e,t,o){var r=arguments.length,i=r<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,t):o,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(n,e,t,o);else for(var c=n.length-1;c>=0;c--)(s=n[c])&&(i=(r<3?s(i):r>3?s(e,t,i):s(e,t))||i);return r>3&&i&&Object.defineProperty(e,t,i),i},l={square:"bmatrix",round:"pmatrix",bar:"vmatrix",double:"Vmatrix",curly:"Bmatrix",none:"matrix"};function h(n,e="square"){let t=n.filter(r=>Array.isArray(r)&&r.length>0);if(t.length===0)return"";let o=l[e]??l.square;return`\\begin{${o}} ${t.map(r=>r.join(" & ")).join(" \\\\ ")} \\end{${o}}`}function m(n,e,t){return t<1?n:e}var a=class extends d{constructor(e){super(e)}entriesTo(e){let t=e.data?.entries;return this.to({data:t===void 0?{}:{entries:t},duration:e.duration,easing:e.easing})}_source(e={}){return h(e.entries??this.entries,e.brackets??this.brackets)}_sourceProps(e={}){return{entries:e.entries??this.entries,brackets:e.brackets??this.brackets}}_resets(e){return e.entries!==void 0||e.brackets!==void 0||e.fontSize!==void 0}};u([f({default:[["a","b"],["c","d"]],tween:m})],a.prototype,"entries",void 0);u([f({default:"square",options:["square","round","bar","double","curly","none"],animatable:!1})],a.prototype,"brackets",void 0);u([p({args:["entries"]})],a.prototype,"entriesTo",null);a=u([b({key:"latexMatrix",parentKey:"latex",forkable:!0,layout:{children:"freeform",defaultWidthMode:"hug",defaultHeightMode:"hug",acceptsChildren:!0},seed:{fill:[{type:"solid",color:[.412,.565,.867,1],opacity:1,enabled:!0}]}})],a);export{h as a,a as b};
2
+ //# sourceMappingURL=chunk-D5WHCVBC.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/tex/matrix.ts"],
4
+ "sourcesContent": ["import { command, node, property, type Command, type CommandArgs, type NodeConfig } from \"@motionscript/sdk\";\r\nimport { Latex, type LatexProps } from \"./node\";\r\n\r\nexport type MatrixBrackets = \"square\" | \"round\" | \"bar\" | \"double\" | \"curly\" | \"none\";\r\n\r\nexport interface LatexMatrixProps extends LatexProps {\r\n entries: string[][];\r\n brackets: MatrixBrackets;\r\n}\r\n\r\nconst ENVIRONMENT: Record<MatrixBrackets, string> = {\r\n square: \"bmatrix\",\r\n round: \"pmatrix\",\r\n bar: \"vmatrix\",\r\n double: \"Vmatrix\",\r\n curly: \"Bmatrix\",\r\n none: \"matrix\",\r\n};\r\n\r\n/** The LaTeX a matrix of `entries` is typeset from; empty for one with no entries. */\r\nexport function matrixSource(entries: readonly (readonly string[])[], brackets: MatrixBrackets = \"square\"): string {\r\n const rows = entries.filter((row) => Array.isArray(row) && row.length > 0);\r\n if (rows.length === 0) return \"\";\r\n const environment = ENVIRONMENT[brackets] ?? ENVIRONMENT.square;\r\n return `\\\\begin{${environment}} ${rows.map((row) => row.join(\" & \")).join(\" \\\\\\\\ \")} \\\\end{${environment}}`;\r\n}\r\n\r\n// A list of rows is a whole value: it changes at the end of a tween, and the morph draws the way there.\r\n// (A function, not a generic arrow: a copied component is compiled as TSX, where `<T>(` opens an element.)\r\nfunction atTheEnd<T>(from: T, to: T, t: number): T {\r\n return t < 1 ? from : to;\r\n}\r\n\r\ntype MatrixNext = Partial<LatexMatrixProps>;\r\n\r\n/**\r\n * A matrix typeset from its entries, row by row, inside the brackets it is\r\n * given. Each entry is a piece of LaTeX and is one of the formula's parts, so\r\n * it can be painted, boxed or braced by its own source.\r\n */\r\n@node({\r\n key: \"latexMatrix\",\r\n parentKey: \"latex\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: true },\r\n seed: { fill: [{ type: \"solid\", color: [0.412, 0.565, 0.867, 1], opacity: 1, enabled: true }] },\r\n})\r\nexport class LatexMatrix extends Latex {\r\n @property({ default: [[\"a\", \"b\"], [\"c\", \"d\"]], tween: atTheEnd }) declare entries: string[][];\r\n @property({ default: \"square\", options: [\"square\", \"round\", \"bar\", \"double\", \"curly\", \"none\"], animatable: false })\r\n declare brackets: MatrixBrackets;\r\n\r\n constructor(props?: NodeConfig<LatexMatrix, LatexMatrixProps>) {\r\n super(props as never);\r\n }\r\n\r\n /** Change the entries: the ones both matrices write travel, the rest fade. */\r\n @command({ args: [\"entries\"] })\r\n entriesTo(args: CommandArgs<{ entries: string[][] }> & { duration: number }): Command<LatexProps> {\r\n const entries = args.data?.entries;\r\n return this.to({ data: (entries === undefined ? {} : { entries }) as Partial<LatexProps>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n override _source(next: MatrixNext = {}): string {\r\n return matrixSource(next.entries ?? this.entries, next.brackets ?? this.brackets);\r\n }\r\n\r\n override _sourceProps(next: MatrixNext = {}): Partial<LatexProps> {\r\n return { entries: next.entries ?? this.entries, brackets: next.brackets ?? this.brackets } as Partial<LatexProps>;\r\n }\r\n\r\n override _resets(next: MatrixNext): boolean {\r\n return next.entries !== undefined || next.brackets !== undefined || next.fontSize !== undefined;\r\n }\r\n}\r\n"],
5
+ "mappings": "wCAAA,OAAS,WAAAA,EAAS,QAAAC,EAAM,YAAAC,MAAiE,8VAUnFC,EAA8C,CAChD,OAAQ,UACR,MAAO,UACP,IAAK,UACL,OAAQ,UACR,MAAO,UACP,KAAM,UAIJ,SAAUC,EAAaC,EAAyCC,EAA2B,SAAQ,CACrG,IAAMC,EAAOF,EAAQ,OAAQG,GAAQ,MAAM,QAAQA,CAAG,GAAKA,EAAI,OAAS,CAAC,EACzE,GAAID,EAAK,SAAW,EAAG,MAAO,GAC9B,IAAME,EAAcN,EAAYG,CAAQ,GAAKH,EAAY,OACzD,MAAO,WAAWM,CAAW,KAAKF,EAAK,IAAKC,GAAQA,EAAI,KAAK,KAAK,CAAC,EAAE,KAAK,QAAQ,CAAC,UAAUC,CAAW,GAC5G,CAIA,SAASC,EAAYC,EAASC,EAAO,EAAS,CAC1C,OAAO,EAAI,EAAID,EAAOC,CAC1B,CAgBO,IAAMC,EAAN,cAA0BC,CAAK,CAKlC,YAAYC,EAAiD,CACzD,MAAMA,CAAc,CACxB,CAIA,UAAUC,EAAiE,CACvE,IAAMX,EAAUW,EAAK,MAAM,QAC3B,OAAO,KAAK,GAAG,CAAE,KAAOX,IAAY,OAAY,CAAA,EAAK,CAAE,QAAAA,CAAO,EAA4B,SAAUW,EAAK,SAAU,OAAQA,EAAK,MAAM,CAAE,CAC5I,CAES,QAAQC,EAAmB,CAAA,EAAE,CAClC,OAAOb,EAAaa,EAAK,SAAW,KAAK,QAASA,EAAK,UAAY,KAAK,QAAQ,CACpF,CAES,aAAaA,EAAmB,CAAA,EAAE,CACvC,MAAO,CAAE,QAASA,EAAK,SAAW,KAAK,QAAS,SAAUA,EAAK,UAAY,KAAK,QAAQ,CAC5F,CAES,QAAQA,EAAgB,CAC7B,OAAOA,EAAK,UAAY,QAAaA,EAAK,WAAa,QAAaA,EAAK,WAAa,MAC1F,GAzB0EC,EAAA,CAAzEC,EAAS,CAAE,QAAS,CAAC,CAAC,IAAK,GAAG,EAAG,CAAC,IAAK,GAAG,CAAC,EAAG,MAAOT,CAAQ,CAAE,iCAExDQ,EAAA,CADPC,EAAS,CAAE,QAAS,SAAU,QAAS,CAAC,SAAU,QAAS,MAAO,SAAU,QAAS,MAAM,EAAG,WAAY,EAAK,CAAE,kCASlHD,EAAA,CADCE,EAAQ,CAAE,KAAM,CAAC,SAAS,CAAC,CAAE,iCAVrBP,EAAWK,EAAA,CAPvBG,EAAK,CACF,IAAK,cACL,UAAW,QACX,SAAU,GACV,OAAQ,CAAE,SAAU,WAAY,iBAAkB,MAAO,kBAAmB,MAAO,gBAAiB,EAAI,EACxG,KAAM,CAAE,KAAM,CAAC,CAAE,KAAM,QAAS,MAAO,CAAC,KAAO,KAAO,KAAO,CAAC,EAAG,QAAS,EAAG,QAAS,EAAI,CAAE,CAAC,EAChG,GACYR,CAAW",
6
+ "names": ["command", "node", "property", "ENVIRONMENT", "matrixSource", "entries", "brackets", "rows", "row", "environment", "atTheEnd", "from", "to", "LatexMatrix", "Latex", "props", "args", "next", "__decorate", "property", "command", "node"]
7
+ }